D.Denton
D.Denton

Reputation: 71

Tkinter module - program will just run then stop and won't open the window

I need help, I am doing a budget calculator and using tkinter for the first time and wondered why it is not working...

When I run it, it will just end straight away and when I put the root = Tk() at the end it comes up with an error.

I really need help, my code is below...

from time import sleep
from tkinter import * 
from tkinter import messagebox, ttk, Tk

root = Tk()

class GUI():

    def taskbar(self):

        menu = Menu()
        file = Menu(menu)
        file.add_command(label="Exit", command=self.exit_GUI)
        file.add_command(label = "Information", command=self.info_popup)        

    def Main_Menu(self):
        topFrame = Frame(root)
        topFrame.pack()
        bottomFrame = Frame(root)
        bottomFrame.pack(side=BOTTOM)

        Income_button = Button(topFrame, text="Enter your incomes", command=self.Income)
        Expense_button = Button(topFrame, text="Enter your expenses", command=self.Expense)
        Total_button = Button(bottomFrame, text="View Results", command=self.Total)
        Income_button.pack()
        Expense_button.pack()
        Total_button.pack()

    def Income(self):
        pass

    def Expense(self):
        pass

    def Total(self):
        pass

    def exit_GUI(self):
        exit()

    def info_popup():
        pass

g = GUI()
g.Main_Menu()
g.taskbar()
g.Income()
g.Expense()
g.Total()
g.exit_GUI()
g.info_popup()

root.mainloop()

Upvotes: 2

Views: 52

Answers (1)

brady
brady

Reputation: 2257

You are exiting before you ever get to the mainloop with:

g.exit_GUI()

That method is calling the standard exit() and stopping the entire script. Remove or comment out the above call. You will also need to add self as an argument to info_popup to get your script to run:

def info_popup(self):
    pass

Upvotes: 4

Related Questions