简体   繁体   中英

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. I found this code on 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

However when I run the program on my computer what I see is this: 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.

It works like TutorialsPoint's on my computer just fine! 在此处输入图片说明

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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