【问题标题】:Positioning text inside OptionMenu in tkinter python在 tkinter python 中的 OptionMenu 内定位文本
【发布时间】:2021-03-08 12:26:59
【问题描述】:

我正在开发 tkinter python 项目。

我正在尝试使用锚选项将文本定位到 OptionMenu 内的左侧,但它似乎不起作用。我正在使用 ttk 主题小部件。

这是我目前正在尝试的代码。

s = ttk.Style()
s.configure('my.TMenubutton', font=("Cambria", fontSize, "bold"), background="white", anchor = W  )
shapeMenu = ttk.OptionMenu(shapeFrame, shape, myShapes[1], *myShapes, style='my.TMenubutton', command=getShapes)

我做错了什么?

【问题讨论】:

    标签: python tkinter ttk tkinter-menu ttkwidgets


    【解决方案1】:

    TMenubutton 下似乎没有锚选项。我试过TLabel,它奏效了。不知道有没有副作用。

    import tkinter as tk
    from tkinter import ttk
    
    root = tk.Tk()
    root.geometry('300x100')
    CHART_TYPES = ('Reticle', 'Circle Grid', 'Checkerboard', 'Grille', 'Slanted Edge MTF')
    
    s = ttk.Style()
    s.configure('my.TLabel', font=("Cambria", 10, "bold"), background="white", anchor = 'w'  )
    
    chart_type = tk.StringVar()
    chart_type.set(CHART_TYPES[0])
    # chart_selector = tk.OptionMenu(root, chart_type, *CHART_TYPES)
    chart_selector = ttk.OptionMenu(root, chart_type, *CHART_TYPES, style='my.TLabel')
    # chart_selector.configure(anchor='w')
    chart_selector.pack(expand=True, fill='x')
    
    root.mainloop()
    

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 2019-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 2020-12-28
      • 1970-01-01
      相关资源
      最近更新 更多