Tkinter菜单中的标签和按钮

2024-10-02 00:38:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Tkinter创建了一个带有图像的菜单按钮。我在菜单按钮中添加了一个标签和两个纽扣。什么时候我运行我的应用程序,它工作正常,直到我点击两次菜单按钮。它开始滞后,然后崩溃。你知道吗

这是我的密码:

from Tkinter import *
from PIL import ImageTk

def donothing():
    print("NOTHING")

root = Tk()
root.geometry("300x300")

Menu_Photo = Menubutton(root)
Photo = ImageTk.PhotoImage(file="image.png")
Menu_Photo.config(image=Photo)
Menu_Photo.image = Photo
Menu_Photo.menu = Menu(Menu_Photo, tearoff=0, relief=FLAT)
Menu_Photo["menu"] = Menu_Photo.menu
Menu_Photo.menu.label = Label(Menu_Photo.menu, text="Menu")
Menu_Photo.menu.Settings = Button(Menu_Photo.menu, text="Settings", relief=FLAT, command=donothing)
Menu_Photo.menu.Sign_Out = Button(Menu_Photo.menu, text="Sign Out", relief=FLAT, command=donothing)
Menu_Photo.menu.label.pack()
Menu_Photo.menu.Settings.pack(fill=BOTH)
Menu_Photo.menu.Sign_Out.pack(fill=BOTH)
Menu_Photo.pack(side=RIGHT, anchor=N)

root.mainloop()

我真的不明白有什么问题?你知道吗

对我来说就是这样:

ErrorError 菜单每秒打开和关闭一次。你知道吗


Tags: textimagesettings菜单rootout按钮pack

热门问题