我正在尝试编写一个程序,用户可以使用 Tkinter 在 Python 中创建时间表。现在,我正在尝试为基本上“主菜单”设置 GUI,用户可以在其中单击按钮并打开另一个窗口或下一个任务所需的任何内容。但是,我的程序会自动运行我在功能下的内容。我该如何解决这个问题?当我尝试 google 时,我找不到任何结果,因为许多人没有展示如何将 GUI 定义为一个类。
from tkinter import *
from tkinter.filedialog import askopenfilename
def loadTable():
filename = askopenfilename(filetypes=[("allfiles","*")])
def addCourse():
print("Insert functionality here")
def addTime():
print("Insert functionality here")
def resetTable():
print("Insert functionality here")
def addComment():
print("Insert functionality here")
def viewTable():
print("Insert functionality here")
class menu():
app = Tk()
app.geometry("800x600+200+200")
app.title("Time Tracker")
#load the buttons for UI
bLoad = Button(app, text = "Load Table", command = loadTable())
bCourse = Button(app, text = "Add Course", command = addCourse())
bTime = Button(app, text = "Add Time", command = addTime())
bReset = Button(app, text = "Reset Time", command = resetTable())
bComment = Button(app, text = "Add Comment", command = addComment())
bView = Button(app, text = "View Table", command = viewTable())
bLoad.pack(side="top", anchor = "w", padx=15, pady=35)
bCourse.pack(side="top", anchor = "w", padx=15, pady=35)
bTime.pack(side="top", anchor = "w", padx=15, pady=35)
bReset.pack(side="top", anchor = "w", padx=15, pady=35)
bComment.pack(side="top", anchor = "w", padx=15, pady=35)
bView.pack(side="top", anchor = "w", padx=15, pady=35)
if __name__ == '__main__':
mainloop()