2

I have a problem with a gui in python, the program executes the command option from the button creation automatic. so i get stuck in a loop. ''' 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)
3
  • you know you can do single line comments like # so - instead of ''' comment ''' ? Commented Mar 11, 2012 at 19:58
  • 2
    @Alex, he's doing it right. Strings in that position become the function's help text ("docstring"). Commented Mar 11, 2012 at 20:06
  • @alexis - ah, right - did not know that :) Commented Mar 11, 2012 at 20:11

1 Answer 1

1

When you link the commands, do it without the () so command=self.action, like this. Also this line seems to be giving you some trouble self.quitAll()... not sure what your trying to do with it but that's my two cents.

''' 
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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.