Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
945 views
in Technique[技术] by (71.8m points)

tkinter - Changing ttk Button Height in Python

This seems like a silly question, but is it possible to change the height of a ttk button manually?

Something like button = tkinter.Button(frame, text='hi', width=20, height=20...) works just fine for a tkinter button. Though I'd prefer to use a ttk button since it looks much better aesthetically.

button = ttk.Button(frame, text='hi', width=20, height=20...) does not work, height doesn't seem to be a valid option. I've tried setting it with config or looking for elements in the style to change and haven't had any luck.

Is there a simple solution to this? I'm using Python 2.7, Windows for the record. Sorry, this seems like kind of a trivial questions but I've looked around without much luck.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This worked for me:

my_button = ttk.Button(self, text="Hello World !")
my_button.grid(row=1, column=1, ipady=10, ipadx=10)

where ipady and ipadx adds pixels inside the button unlike pady and padx which adds pixels outside of the button


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...