0
私は自分自身で解決できなかった問題をtkinterから取り除きました。
私は自分でウィジェットを作成したいと思っていました。私はポケットを呼ぶ。効果的に開いているか隠れていることができる私の窓の一部です。AttributeError: 'NoneType'オブジェクトに__init__.pyの 'children'属性がありません。
class pocket(tk.Frame):
def __init__(self, parent, master=None, expand_Bool=True):
tk.Frame.__init__(self, parent)
self.master = master
self.Content = tk.Frame(self)
self.Button_on = tk.Button(self,text='Open',command=lambda: self.expand())
self.Button_hide = tk.Button(self,text='Hide',command=lambda: self.hide())
self.Content.grid(row=1,column=0)
self.Button_on.grid(row=0,column=0)
self.Button_hide.grid(row=0,column=0)
if expand_Bool:
self.expand()
else:
self.hide()
def expand(self):
self.Button_on.grid_remove()
self.Button_hide.grid()
self.Content.grid()
def hide(self):
self.Button_on.grid()
self.Button_hide.grid_remove()
self.Content.grid_remove()
def get_contentframe(self):
return self.Content
if __name__=='__main__':
root=tk.Tk()
pocket1 =pocket(root)
pocket1.grid(row=0,column=0)
label1=tk.Label(pocket1.get_contentframe(),text='Text')
label1.grid(row=1,column=1)
root.mainloop()
「ウィジェット」自体は静かにうまく動作します。ウィンドウを閉じようとすると、エラーメッセージが表示されます。
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\...\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\...\tkinter\__init__.py", line 2055, in destroy
for c in list(self.children.values()): c.destroy()
File "C:\...\tkinter\__init__.py", line 2300, in destroy
if self._name in self.master.children:
AttributeError: 'NoneType' object has no attribute 'children'
このエラーを回避するにはどうすればよいですか?またはこれを行うためのより良い方法がありますか?
ありがとうございます。
挨拶
あなたは 'tkinter.after()'や 'threads'を使うのですか?プログラムを終了する前に、プログラムを停止する必要があるかもしれません。 – furas
BWT: 'command = lambda:self.expand()' 'command = self.expand'(' lambda'と '()'を除く) – furas
BTW:[PEP 8スタイルガイドfor Python Code ](https://www.python.org/dev/peps/pep-0008/) – furas