0
私のコードはいくつかのウィジェットを破壊し、新しいウィジェットを作成します。そして、アプリケーションの最後にボタンを押して最初に行きたいかどうかを尋ねます。このボタンは、すべての変数を再初期化し、同じ古いウィジェットを再描画するクラスコンストラクターを呼び出します。問題は、たとえ新しいものであってもウィジェットが破壊前に最新の値を保持していることです。例えば、このコードではTkinterウィジェットは、破棄されて再構築された後の状態を保持します
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)
マッピングは新しいサイクルに戻って呼び出されたときに、マッピングのチェックボタンは、その最新の値を保持します。
私が最初に作成されたかのように、チェックボタンを新しくしたいです。
あなたはvariable
属性のため、通常の変数を使用することはできませんあなたの助け
こんにちは、変数がタプルの場合、どうすればよいですか? –
@TarikMokafih: 'variable'属性を使ってタプルを' Checkbutton'に関連付けることはできません。特別なtkinter変数オブジェクトの1つでなければなりません。 –