2012-03-11 3 views
2

У меня проблема с gui в python, программа выполняет команду из автоматического создания кнопки. поэтому я застреваю в петле. ''» Созданный на 5-mrt.-2012Python GUI с Tkinter

@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' '' '? –

+2

@ Алекс, он делает все правильно. Строки в этом положении становятся текстом справки функции («docstring»). – alexis

+0

@alexis - ах, справа - не знал, что :) –

ответ

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)