构建简单的python GUI以打开MP3
很抱歉,问题陈述不好。我的问题是,我试图创建一个菜单栏,使用window的内置文件浏览器打开MP3。GUI出现,但菜单不存在,只有GUI窗口。但是没有语法错误。目标是在文件菜单中创建打开按钮和退出按钮。下面的所有代码都是完整的代码 “”“ 音乐播放器 “”“构建简单的python GUI以打开MP3,python,user-interface,tkinter,Python,User Interface,Tkinter,很抱歉,问题陈述不好。我的问题是,我试图创建一个菜单栏,使用window的内置文件浏览器打开MP3。GUI出现,但菜单不存在,只有GUI窗口。但是没有语法错误。目标是在文件菜单中创建打开按钮和退出按钮。下面的所有代码都是完整的代码 “”“ 音乐播放器 “”“ 代码重用可以为您节省大量时间,但您必须确保所有这些都适合您。这意味着将诸如self.master到app和self.client\u exit之类的引用更正为调用“打开”函数的任何函数 from tkinter import * app =
代码重用可以为您节省大量时间,但您必须确保所有这些都适合您。这意味着将诸如
self.master
到app
和self.client\u exit
之类的引用更正为调用“打开”函数的任何函数
from tkinter import *
app = Tk()
app.geometry("600x200")
menu = Menu(app)
file = Menu(menu)
file.add_command(label='Open', command=print) # replace 'print' with the name of your open function
file.add_command(label='Exit', command=app.destroy) # closes the tkinter window, ending the app
menu.add_cascade(label='File', menu=file)
app.config(menu=menu)
app.mainloop() # at the end
此代码段是否取自类中?如果没有,您不应该使用“self”,因为它不是来自类,如果整个GUI没有出现,您需要提供一个更完整的代码示例。请阅读,并为此问题创建一个示例。您向我们提供了一个随机代码片段,没有解释,没有任何错误的详细信息,没有正在使用的对象的定义,什么都没有。请为您的问题提供更多信息,以便我们可以A)复制您的问题,B)帮助您解决问题。
from tkinter import *
app = Tk()
app.geometry("600x200")
menu = Menu(app)
file = Menu(menu)
file.add_command(label='Open', command=print) # replace 'print' with the name of your open function
file.add_command(label='Exit', command=app.destroy) # closes the tkinter window, ending the app
menu.add_cascade(label='File', menu=file)
app.config(menu=menu)
app.mainloop() # at the end