2012-03-11 134 views
2

我有一個在python中的GUI問題,程序從按鈕創建自動執行命令選項。所以我陷入了一個循環。 ''」創建於5 mrt.-2012與Tkinter的Python圖形用戶界面

@author: Max 
''' 
from Tkinter import * 


class main(Tk): 
    def __init__(self,parent): 
     self.mainWindow() 
    def mainWindow(self): 
     '''Make the main window ''' 
     self.quitAll() 
     self.app = Tk() 
     self.app.title('NMBS application') 
     self.makeAppButtons() 
     self.finish(self.app) 
    def makeAppButtons(self): 
     '''Make all the buttons for the main menu''' 
     button_lijn = Button(self.app, text="Voeg lijnritten toe", command = self.lijnritten()) 
     button_lijn.pack() 
    def finish(self,window): 
     ''' Make the main window''' 
     window.mainloop() 
    def endButton(self,window): 
     '''Make a quit button''' 
     button_back = Button(window,text="Sluiten",command = self.mainWindow()) 
     button_back.pack() 
    def quitAll(self): 
     '''Close all the current windows''' 
     self.lijn_window.quit() 
     self.app.quit() 
    def lijnritten(self): 
     ''' Make the lijnritten window''' 
     self.app.quit() 
     self.lijn_window = Tk() 
     self.lijn_window.title("lijnritten") 
     self.endButton(self.lijn_window) 
     self.finish(self.lijn_window) 
main(None) 
+0

你知道你可以做像'#so'這樣的單行註釋 - 而不是''''comment'''''? – 2012-03-11 19:58:07

+2

@Alex,他做得很對。該位置的字符串變成函數的幫助文本(「文檔字符串」)。 – alexis 2012-03-11 20:06:05

+0

@alexis - 啊,對 - 不知道:) – 2012-03-11 20:11:28

回答

1

當你鏈接的命令,這樣做沒有(),所以command=self.action,像這樣。另外這條線似乎給你帶來一些麻煩self.quitAll() ......不確定你想用它做什麼,但那是我的兩分錢。

''' 
Created on 5-mrt.-2012 
@author: Max 
''' 
from Tkinter import * 


class main(Tk): 
    def __init__(self,parent): 
     self.mainWindow() 
    def mainWindow(self): 
     '''Make the main window ''' 
     #self.quitAll() 
     self.app = Tk() 
     self.app.title('NMBS application') 
     self.makeAppButtons() 
     self.finish(self.app) 
    def makeAppButtons(self): 
     '''Make all the buttons for the main menu''' 
     button_lijn = Button(self.app, text="Voeg lijnritten toe", command = self.lijnritten) 
     button_lijn.pack() 
    def finish(self,window): 
     ''' Make the main window''' 
     window.mainloop() 
    def endButton(self,window): 
     '''Make a quit button''' 
     button_back = Button(window,text="Sluiten",command = self.mainWindow) 
     button_back.pack() 
    def quitAll(self): 
     '''Close all the current windows''' 
     self.lijn_window.quit() 
     self.app.quit() 
    def lijnritten(self): 
     ''' Make the lijnritten window''' 
     self.app.quit() 
     self.lijn_window = Tk() 
     self.lijn_window.title("lijnritten") 
     self.endButton(self.lijn_window) 
     self.finish(self.lijn_window) 
main(None)