【问题标题】:How to control location of drop down menu in Tkinter?如何控制 Tkinter 中下拉菜单的位置?
【发布时间】:2016-06-09 21:37:33
【问题描述】:

我正在尝试更改 Tkinter 中下拉菜单的呈现方式。我在 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()

根据站点,呈现的菜单应如下所示:Dropdown Menu Image Web

但是,当我在计算机上运行该程序时,我看到的是:Dropdown Menu Image Local

我有什么方法可以强制网络版本中显示的行为,其中每个下拉菜单从菜单按钮的左角向右延伸,而不是从菜单按钮的右上角向左延伸?

【问题讨论】:

    标签: python python-3.x user-interface tkinter


    【解决方案1】:

    我猜这与您计算机上的设置有关,而不是 tkinter/Python。

    它就像我电脑上的 TutorialsPoint 一样工作得很好!

    需要记住的一点...(也许这适用?)根据您的下拉窗口所在的位置,下拉菜单的方向会发生变化(这是我靠近显示器边缘的窗口)

    如果我有决斗监视器,我也会对其进行测试。希望这会有所帮助。

    【讨论】:

    • 你确实是对的。我有一个要测试的 Ubuntu 发行版,它的渲染效果如网站上所示。我正在 Windows 8 上测试/开发(不幸的是),我不知道为什么会这样。无论哪种情况,听起来都超出了我的控制范围。感谢您的回复!
    • 我在开发一个 tkinter 应用程序的同时,在 Windows 10 上打开了一个关于同样事情的答案。同样的问题。告诉这是本地问题,而不是 tkinter python。我认为这是 Windows 10 上的一个错误,或者可能是因为双显示器。我也有双显示器。嗯,值得研究。
    • 是的,如果这个错误发生在我身上,我会非常生气:\
    【解决方案2】:

    我的桌面 Windows 8.1 系统遇到了这个问题。

    我修好了

    1. 进入控制面板,平板电脑设置
    2. 单击“其他”选项卡并将“惯用手”选项设置为“左撇子”
    3. 单击“应用”按钮。

    查看此链接了解更多信息:https://www.askvg.com/how-to-change-menu-position-from-left-to-right-in-windows-vista/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      相关资源
      最近更新 更多