【问题标题】:Python 3.4, How to increase the size of the tkinter spinbox widget arrowheads?Python 3.4,如何增加 tkinter spinbox 小部件箭头的大小?
【发布时间】:2015-06-10 09:23:57
【问题描述】:

如何增加 tkinter spinbox 箭头的大小?

root = Tk()
Rtitle = Frame(root)

valueChanger = Spinbox(Rtitle, from_=0, to=10, wrap = True, width = 0)

valueChanger.pack(side=RIGHT, padx = 5, ipadx = 2, ipady = 5)

Rtitle.pack(side = TOP, fill=BOTH, expand=True)


root.mainloop()

提前致谢:)

【问题讨论】:

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


    【解决方案1】:

    每个箭头按钮都是盒子高度的一半。通过增加字体大小来增加框的高度。最小的完整可验证示例(人们在提问时应该发布的那种;-):

    from tkinter import *
    from tkinter.font import Font
    
    root = Tk()
    spin = Spinbox(root, from_=0, to=9, width=3,
                   font=Font(family='Helvetica', size=36, weight='bold'))
    spin.pack()
    

    【讨论】:

    • 我通过实验得知了答案,从Spinbox(root)开始,没有导入字体。在我尝试之前,我不确定用大字体扩展框会扩展箭头框,而不是在它们之间放置空格。
    • 尝试一下是个好主意,我是 Tkinter 的新手,看来实验是关键。再次感谢。
    【解决方案2】:

    如果你使用ttk,你可以在不改变字体的情况下配置arrowsize。 (我在 OS X 上,所以我也需要设置主题。)

    import tkinter as tk
    import tkinter.ttk as ttk
    
    root = tk.Tk()
    style = ttk.Style()
    style.theme_use('default')
    style.configure('My.TSpinbox', arrowsize=15)
    
    sb1 = ttk.Spinbox(root, style='TSpinbox', from_=1, to=5)
    sb1.grid()
    
    sb2 = ttk.Spinbox(root, style='My.TSpinbox', from_=1, to=5)
    sb2.grid()
    
    root.mainloop()
    

    【讨论】:

      猜你喜欢
      • 2011-03-02
      • 2019-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-26
      • 1970-01-01
      • 2011-05-13
      相关资源
      最近更新 更多