如何在Tkinter中控制下拉菜单的位置?
问题描述:
我想改变Tkinter中的下拉菜单似乎呈现的方式。我发现TutorialsPoint此代码:如何在Tkinter中控制下拉菜单的位置?
from Tkinter import *
def donothing():
filewin = Toplevel(root)
button = Button(filewin, text="Do nothing button")
button.pack()
root = Tk()
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="New", command=donothing)
filemenu.add_command(label="Open", command=donothing)
filemenu.add_command(label="Save", command=donothing)
filemenu.add_command(label="Save as...", command=donothing)
filemenu.add_command(label="Close", command=donothing)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Undo", command=donothing)
editmenu.add_separator()
editmenu.add_command(label="Cut", command=donothing)
editmenu.add_command(label="Copy", command=donothing)
editmenu.add_command(label="Paste", command=donothing)
editmenu.add_command(label="Delete", command=donothing)
editmenu.add_command(label="Select All", command=donothing)
menubar.add_cascade(label="Edit", menu=editmenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="Help Index", command=donothing)
helpmenu.add_command(label="About...", command=donothing)
menubar.add_cascade(label="Help", menu=helpmenu)
root.config(menu=menubar)
root.mainloop()
根据现场呈现应该是这样的菜单:Dropdown Menu Image Web
然而,当我运行我的计算机上的程序我所看到的是这样的:Dropdown Menu Image Local
有没有什么方法可以强制网络版本中显示的行为,其中每个下拉菜单都从菜单按钮的左侧角度向右侧延伸,而不是从菜单按钮的右侧角度向左侧延伸?
你确实是对的。我有一个Ubuntu发行版来测试,并且它在网站上显示。我正在测试/开发Windows 8(不幸),我不知道为什么它会这样做。无论如何,这听起来好像是超出了我的控制范围。感谢您的答复! –
我在开发一个tkinter应用程序时,在字面上开了一个关于windows 10上同样的东西的答案。同样的问题。告诉说,这是本地问题,而不是tkinter蟒蛇。我认为这是Windows 10的一个bug,或者可能是因为双显示器。我也有双显示器。嗯,值得研究。 –
是的,如果它发生在我身上,我会对这个bug非常恼火:\ –