Python Tkinter模块-任务栏未显示
有人知道为什么它不会在我的代码中显示任务栏吗。我试图在文件下拉菜单的顶部显示退出和信息。我是tkinter的新手,我只是需要一些帮助。另外,如果您对如何改进它有任何建议,我将非常感谢 我的代码如下:Python Tkinter模块-任务栏未显示,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,有人知道为什么它不会在我的代码中显示任务栏吗。我试图在文件下拉菜单的顶部显示退出和信息。我是tkinter的新手,我只是需要一些帮助。另外,如果您对如何改进它有任何建议,我将非常感谢 我的代码如下: from time import sleep from tkinter import * from tkinter import messagebox, ttk, Tk root = Tk() class GUI(): def taskbar(self): menu
from time import sleep
from tkinter import *
from tkinter import messagebox, ttk, Tk
root = Tk()
class GUI():
def taskbar(self):
menu = Menu(root)
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(self):
pass
g = GUI()
g.taskbar()
g.Main_Menu()
g.Income()
g.Expense()
g.Total()
g.info_popup()
root.mainloop()
您需要将
任务栏
功能更改为:
def taskbar(self):
menu = Menu(root)
file = Menu(menu)
file.add_command(label="Exit", command=self.exit_GUI)
file.add_command(label = "Information", command=self.info_popup)
root.config(menu=file)
这将告诉窗口使用菜单栏。您忘记了告诉窗口实际使用菜单栏的
root.config(menu=menu)
。@jasonharper没有工作,它说菜单没有定义您需要在实际定义menu
的地方执行此操作,然后,它停止向我提供错误,但在脚本运行时仍然没有显示