Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter模块-程序将运行,然后停止并赢得';Don’不要打开窗户_Python_Python 3.x_Tkinter - Fatal编程技术网

Python Tkinter模块-程序将运行,然后停止并赢得';Don’不要打开窗户

Python Tkinter模块-程序将运行,然后停止并赢得';Don’不要打开窗户,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我需要帮助,我正在做一个预算计算器,第一次使用tkinter,我想知道为什么它不起作用 当我运行它时,它将直接结束,当我将root=Tk()放在末尾时,它会出现一个错误 我真的需要帮助,我的代码如下 from time import sleep from tkinter import * from tkinter import messagebox, ttk, Tk root = Tk() class GUI(): def taskbar(self): menu

我需要帮助,我正在做一个预算计算器,第一次使用
tkinter
,我想知道为什么它不起作用

当我运行它时,它将直接结束,当我将
root=Tk()
放在末尾时,它会出现一个错误

我真的需要帮助,我的代码如下

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()

在进入
mainloop
之前,您将退出:

g.exit_GUI()
该方法调用标准的
exit()
并停止整个脚本。删除或注释掉上述调用。您还需要将
self
作为参数添加到
info\u popup
以运行脚本:

def info_popup(self):
    pass

虽然这可能有效,但我不建议在
GUI()
中引用的全局范围中有一个
root
,不过,这感觉像是一个滑坡。当然,这不是问题的一部分。