我想写一个程序,用户可以在Python中使用Tkinter创建时间表。现在,我试图设置基本上是“主菜单”的图形用户界面,用户可以点击按钮并调出另一个窗口或下一个任务所需的任何窗口。但是,我的程序会自动运行我在这些功能下的功能。我该如何解决这个问题?当我尝试谷歌时,我找不到任何结果,因为很多程序没有显示如何将GUI定义为类。Tkinter按钮
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()
更多的代码。你提供的代码并没有传达太多的东西来产生你得到的相同的不良行为。 –
@Ashish Nitin Patil基本上我想让按钮调用一个函数,当我点击它们。然而,当我在这个状态下运行程序时,所有的函数都会运行,所以闲置的shell会获得所有的打印语句和文件管理器弹出。我基本上想在这一点上解决这个问题。不过,我打算可能使其中一个按钮打开一个新窗口,以将信息添加到我的表格中。 – WorldDominator