Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multi line Tkinter button?

Tags:

python

tkinter

i have the following button:

option1=tkinter.Button(opt1,text='this is a test to see how many words we can fit in a button and stuff so heres some more words',width=49,height=3,bg='grey',)

this makes a button which has the words see how many words we can fit in a button and stuff so heres som.

i want the text to move down to the next line instead of going off the side of the button.

also, how can i make it so the text is not centred?

python 3.3.3.

like image 631
Thedudxo Avatar asked Jul 21 '26 03:07

Thedudxo


1 Answers

Using the wraplength option is a good way to make it wrap, and the justify option to do something other than center:

option1 = tkinter.Button(opt1, wraplength=80, justify=LEFT, text='This is the text')

The value of wraplength is in screen units, or pixels. You can also just drop a '\n' character into the middle of your string to break the line manually, but may also have to size the button manually if you do this.

like image 182
Crowman Avatar answered Jul 23 '26 16:07

Crowman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!