我有以下代码:
一种。那里有两个单选按钮。
b。单击一个按钮,然后使用grid_remove()
删除另一个单选按钮。
C。然后添加标签和输入小部件。
d。然后,我尝试执行dictionary['element'].grid()
来取回已删除的小部件,但我看不到它再次放回原处。
#!/usr/intel/bin/python2.7
import Tkinter
from Tkinter import *
class simpleapp_tk(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.entries = {}
self.sc_button = None
self.cv_button = None
self.scl1 = None
self.sce1 = None
self.scl2 = None
self.initialize()
def initialize(self):
self.grid()
initial_screen_buttons = (
('self.sc_button', 'Single Component','v', 1, self.singlecomponent, 4, 'W'),
('self.cv_button', 'Comple Component','v', 2, self.complecomponent, 5, 'W')
)
#entries = []
for _ButtonName , _Text, _Variable, _Value, _Operation, _Row, _Sticky in initial_screen_buttons:
_ButtonName_tmp = Radiobutton(self, anchor="center", text=_Text, variable=_Variable, value=_Value, command=_Operation)
_ButtonName_tmp.grid(row=_Row, sticky=_Sticky)
_ButtonName_tmp.rowconfigure(_Row,weight=1)
self.entries[_ButtonName] =_ButtonName_tmp
print 'Name of the button is ', _ButtonName
print 'Name of the button is ', _ButtonName_tmp
self.grid_columnconfigure(0,weight=1)
self.grid_columnconfigure(1,weight=1)
self.grid_columnconfigure(2,weight=1)
self.grid_rowconfigure(0,weight=1)
self.grid_rowconfigure(1,weight=1)
def singlecomponent(self):
#self.cv_button.grid_forget()
print 'Values in entries', self.entries
print 'Values in entries', self.entries["self.cv_button"]
self.entries['self.cv_button'].grid_remove()
#self.entries[1].grid_forget()
# print "value of v is %d"%v.get()
if not (self.scl1):
self.scl1 = Label(self, text="Enter The Widget Name You Wanted To Create: ")
self.scl1.grid(row=6)
if not (self.sce1):
self.sce1 = Entry(self)
self.sce1.grid(row=7)
if not (self.scl2):
self.scl2 = Label(self, text="Which Widget You Wanted To Create: ")
self.scl2.grid(row=8)
self.entries['self.cv_button'].grid() #Calling the grid back is not getting placed back again.
def complecomponent(self):
#self.sc_button.grid_forget()
print 'Values in entries', self.entries['self.sc_button']
self.entries['self.sc_button'].grid_forget()
#self.entries[0].grid_forget()
if __name__ == "__main__":
app = simpleapp_tk(None)
app.title("Test App")
app.mainloop()
查询:
一种。不会调用grid()来使用grid_remove()取回已删除的小部件吗?
b。还是有更好的解决方案来收回小部件?
任何人都可以评论/建议需要做什么吗?