2013-10-15 69 views
0

我有三個不同的文件三類,通過GUI錯誤:_tkinter.TclError:不能援引「WM」的命令:應用程序已經被破壞

#file1 
class GetInfo1(): 
    def getInfo1(): 
     #my code 
     return info1 
#file2 
class GetInfo2(): 
    def getInfo2(): 
     #my code 
     return info2 
#file3 
class GetInfo3(): 
    def getInfo3(): 
     #my code 
     return info3 

調用不同文件中的這些方法來獲取用戶輸入Getinformation.py 該文件將

from GetInfo1 import * 
from GetInfo2 import * 
from GetInfo3 import * 

object1 = GetInfo1() 
getInfor1 = object1.getInfo1() 
print getInfor1 

object2 = GetInfo2() 
getInfor2 = object2.getInfo2() 
print getInfor2 

object3 = GetInfo3() 
getInfor3 = object3.getInfo3() 
print getInfor3 

類如下:

from Tkinter import * 

root = Tk() 
app = Frame(root) 

entry = Entry(app) 
entry.grid() 


class GetInfo1(): 

def OnClick(self): 
    global input1 
    input1 = entry.get() 
    #print ("You have entered %s"%input1) 
    root.destroy() 
    return input1 

def getInfo1(self): 

    '''Window''' 
    global input1 
    root.title("Input Permutation Range ") 
    root.geometry("300x200") 
    app.grid() 
    label = Label (app, text="Please Enter the propogation range (2 - 4)") 
    label.grid() 

    '''Button''' 
    Object2 = AskPermutationRange() 
    button = Button (app, text="Submit", command=Object2.OnClick) 
    button.grid() 
    root.focus_set() 
    root.mainloop() 
    return input1 

獲取getInfor1,getInfor2如指定,但 運行第三個對象時出現錯誤 _tkinter.TclError: can't invoke "wm" command: application has been destroyed 如何重新調用應用程序。在此先感謝

回答

2

所有這些消息意味着你在銷燬根窗口後調用其中一個「wm」命令(例如:wm_title,wm_geometry和其他一些命令)。 (注意:「幾何」和「標題」是「wm_geometry」和「wm_title」的簡單快捷方式)。

你正在以非常不尋常的方式使用tkinter。 Tkinter是爲您創建一個Tk的單個實例,並且只調用一次mainloop。您有什麼原因需要在應用程序過程中多次停止並啓動Tkinter?如果您只需彈出一些模式對話框並等待用戶輸入數據,則可以在不創建每次Tk的新實例的情況下執行此操作。

+0

是的,現在我得到了解決方案,我把我的代碼整理成一個文件,並調用mainloop()一次! – WEshruth

相關問題