我的代码破坏了一些小部件,然后构建了新的小部件,然后在应用程序的末尾,有一个按钮询问我是否要开始。此按钮将调用类构造函数,该构造函数将重新初始化每个变量并开始重新绘制相同的旧窗口小部件。问题在于,即使是新的小部件,销毁之前仍保留其最新值。
def mapping(self):
sort_frame = Frame(self.top_frame)
sort_frame.grid(row=0,column=1)
sort = False
Checkbutton(sort_frame, text="Sort: ", variable=sort, onvalue=True, offvalue=False,command=lambda fr=sort_option_frame, nx = next_button : self.enable_sort(fr,nx)).pack(side=TOP)
next_button = Button(self.bottom_frame, text='Next',borderwidth=1, command=self.output_select)
next_button.pack( side = RIGHT)
def output_select(self):
for widget in self.top_frame.winfo_children():
widget.destroy()
for widget in self.bottom_frame.winfo_children():
widget.destroy()
#new widgets drawing
Button(self.bottom_frame, text='New file',borderwidth=1, command=self.restart).pack( side = TOP)
#This UI resets the application for a new cycle
def restart(self):
for widget in self.top_frame.winfo_children():
widget.destroy()
for widget in self.bottom_frame.winfo_children():
widget.destroy()
self.__init__(self.root)
例如,在此代码中,在新周期中调用映射时,映射中的Checkbutton将保留其最新值。
我希望该复选按钮是新的,好像它是第一次创建一样。
谢谢你的帮助
您不能对variable
属性使用普通变量。他们需要的一个实例StringVar
,IntVar
,DoubleVar
,或BooleanVar
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句