我需要帮助,我正在做一个预算计算器并第一次使用 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_popup
以使脚本运行:
def info_popup(self):
pass
关于python - Tkinter 模块 - 程序将只运行然后停止并且不会打开窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52898919/