0
我對Python的創建兩個功能:的Python的Tkinter [無法調用命令:應用程序已經被破壞]
- 之一打開一個新的窗口:new_window()
- 另一個創建按鈕就可以了:create_buttons(「文本顯示」)
當我啓動它們,new_window效果很好,但create_button顯示[不能援引「按鈕」的命令:應用程序已被破壞],好像我的主窗口已經摧毀......但我的窗戶仍然開着!
...你有什麼想法嗎?
import Tkinter
from Tkinter import *
def new_window():
master = Tk()
def create_buttons(display):
new_button= Button(master, text=display)
new_button.pack()
new_window() ### OK, CREATES A WINDOW
create_buttons('text') ### DISPLAYS FOLLOWING BUG :
create_buttons('text')
TclError Traceback (most recent call last)
/neurospin/grip/protocols/MRI/childrenDTIreading_Letarnec_2011/tools/data_mysql/<ipython console> in <module>()
/neurospin/grip/protocols/MRI/childrenDTIreading_Letarnec_2011/tools/data_mysql/<ipython console> in create_buttons(display)
/usr/lib/python2.6/lib-tk/Tkinter.pyc in __init__(self, master, cnf, **kw)
2003 overrelief, state, width
2004 """
-> 2005 Widget.__init__(self, master, 'button', cnf, kw)
2006
2007 def tkButtonEnter(self, *dummy):
/usr/lib/python2.6/lib-tk/Tkinter.pyc in __init__(self, master, widgetName, cnf, kw, extra)
1933 del cnf[k]
1934 self.tk.call(
-> 1935 (widgetName, self._w) + extra + self._options(cnf))
1936 for k, v in classes:
1937 k.configure(self, v)
TclError: can't invoke "button" command: application has been destroyed
'master'是'new_window()'中的局部變量。不要在交互式Python控制檯之外使用通配符導入('*')。 – jfs