简体   繁体   English

如何控制 Tkinter 中下拉菜单的位置?

[英]How to control location of drop down menu in Tkinter?

I am trying to change the way that the dropdown menu in Tkinter seems to render.我正在尝试更改 Tkinter 中下拉菜单的呈现方式。 I found this code on TutorialsPoint:我在 TutorialsPoint 上找到了这段代码:

    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()

According the site the menu that renders should look like this: Dropdown Menu Image Web根据该站点,呈现的菜单应如下所示:下拉菜单图像 Web

However when I run the program on my computer what I see is this: Dropdown Menu Image Local但是,当我在计算机上运行该程序时,我看到的是: Dropdown Menu Image Local

Is there any way for me to force the behaviour shown in the version on the web, where every dropdown menu extends from the left corner of the menu button to the right instead of from the right corner of the menu button to the left?有什么办法可以让我强制执行网络版本中显示的行为,其中每个下拉菜单都从菜单按钮的左角向右延伸,而不是从菜单按钮的右角向左延伸?

I'm guessing this has something to do with the settings on your computer and not tkinter/Python.我猜这与您计算机上的设置有关,而不是 tkinter/Python。

It works like TutorialsPoint's on my computer just fine!它在我的电脑上就像 TutorialsPoint 一样工作得很好! 在此处输入图片说明

Something to keep in mind though... (Maybe this applies?) Depending on where your window with the drop-down IS, the orientation of the drop-down changes (This is my window near the edge of my monitor)但是要记住一些事情......(也许这适用?)根据下拉窗口的位置,下拉的方向会发生变化(这是我靠近显示器边缘的窗口)

在此处输入图片说明

If I had duel-monitors I'd test that as well.如果我有决斗监视器,我也会测试它。 Hopefully this helps .希望这会有所帮助。

I had this problem on my Desktop Windows 8.1 system.我在桌面 Windows 8.1 系统上遇到了这个问题。

I fixed it by我修好了

  1. Going to Control Panel, Tablet PC Settings进入控制面板,平板电脑设置
  2. Clicking on the Other tab and setting Handedness option to Left-handed单击其他选项卡并将惯用选项设置为惯用左手
  3. clicking the Apply button.单击应用按钮。

See this link for more information: https://www.askvg.com/how-to-change-menu-position-from-left-to-right-in-windows-vista/有关更多信息,请参阅此链接: https : //www.askvg.com/how-to-change-menu-position-from-left-to-right-in-windows-vista/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM