按钮高度:
如果你注意到,frame_1的高度是30,而按钮的高度分别为100和20。一个按钮的高度比frame_1显著更高。因此,如果你最大化你的tk窗口,你会看到按钮之间的高度差异。或者,尝试将一个按钮的高度设置为10,另一个按钮的高度设置为2,然后重新运行你的脚本,以查看高度差异。结论,按钮的高度可以改变。
按钮横向放置:
按钮的横向放置可以通过使用pack系统的padx=[x_left, x_right]选项来控制。x_left和x_right表示与其父级相关的每个按钮左侧和右侧要留下的水平外部填充。您可以阅读Tk文档以获取有关Packer算法的更清晰的解释。
from tkinter import *
selection_window = Tk()
selection_window.wm_title("")
selection_window.geometry('{}x{}'.format(200, 150))
frame_1 = Frame(selection_window, width=200, height=30)
frame_1.pack()
Button(frame_1, text="Single",height = 10).pack(side=LEFT, anchor=S, padx=[0,40])
Button(frame_1,text="Range",command=Toplevel,height = 2).pack(side=RIGHT, anchor=S, padx=[20,0])
selection_window.mainloop()
高度:
位置:
第二部分:
根据下面的评论,请运行以下脚本,查看在使用“非默认”样式主题时是否可以更改ttk.Button的高度并在评论区发布您的发现。 在我的Ubuntu上可以工作。
from tkinter import *
import tkinter.ttk as ttk
s=ttk.Style()
print('Style themes on my system are ', s.theme_names())
s.theme_use('clam')
s.configure('bb.TButton', background='white', padding=50)
b1=ttk.Button(text='Default')
b1.pack(side=LEFT, anchor=S, padx=[0,40])
b2=ttk.Button(text='Custom', style='bb.TButton')
b2.pack(side=RIGHT, anchor=S, padx=[20,0])
填充=1
填充=40![填充=40](https://istack.dev59.com/HEqRk.webp)
.geometry("200x150")
。 - undefined