【发布时间】:2018-08-17 04:23:55
【问题描述】:
我在杀死使用以下方式创建的 tkinter 窗口时遇到了很多麻烦。我收到如下所示的错误。我对 Python 还很陌生,因此我们将不胜感激。
class InspectWindow(tk.Frame):
def __init__(self, sender_email, recipient_email, email_body,
master = None):
super().__init__(master)
self.create_widgets()
def create_widgets(self):
self.yes = tk.Button(self)
self.yes['text'] = 'send me!'
self.yes['command'] = self.send_email()
def send_email(self):
root.destroy()
root = tk.Tk()
popup = InspectWindow(sender_email, recipient_email, email_body,
master=root)
popup.mainloop()
Traceback (most recent call last):
File "spam.py", line 108, in <module>
master=root)
File "spam.py", line 16, in __init__
self.create_widgets()
File "AutomateFellowshipEmails.py", line 23, in create_widgets
self.yes['command'] = self.send_email()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 1486, in __setitem__
self.configure({key: value})
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 1479, in configure
return self._configure('configure', cnf, kw)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 1470, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".!inspectwindow.!button"
【问题讨论】:
标签: python-3.x inheritance tkinter destroy