簡體   English   中英

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

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

我正在嘗試更改 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()

根據該站點,呈現的菜單應如下所示:下拉菜單圖像 Web

但是,當我在計算機上運行該程序時,我看到的是: Dropdown Menu Image Local

有什么辦法可以讓我強制執行網絡版本中顯示的行為,其中每個下拉菜單都從菜單按鈕的左角向右延伸,而不是從菜單按鈕的右角向左延伸?

我猜這與您計算機上的設置有關,而不是 tkinter/Python。

它在我的電腦上就像 TutorialsPoint 一樣工作得很好! 在此處輸入圖片說明

但是要記住一些事情......(也許這適用?)根據下拉窗口的位置,下拉的方向會發生變化(這是我靠近顯示器邊緣的窗口)

在此處輸入圖片說明

如果我有決斗監視器,我也會測試它。 希望這會有所幫助。

我在桌面 Windows 8.1 系統上遇到了這個問題。

我修好了

  1. 進入控制面板,平板電腦設置
  2. 單擊其他選項卡並將慣用選項設置為慣用左手
  3. 單擊應用按鈕。

有關更多信息,請參閱此鏈接: 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