Skip to main content
 首页 » 编程设计

python之多行 Tkinter 按钮

2025年05月04日17linjiqin

我有以下按钮:

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',) 

这会生成一个按钮,上面有单词 看看我们可以在一个按钮中放入多少个单词等等,所以这里是 som。

我希望文本向下移动到下一行而不是离开按钮的一侧。

另外,我怎样才能使文本不居中?

python 3.3.3.

请您参考如下方法:

使用 wraplength 选项是使其环绕的好方法,使用 justify 选项可以做中心以外的事情:

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

wraplength 的值以屏幕单位或像素为单位。您也可以将 '\n' 字符放入字符串中间以手动换行,但如果您这样做,可能还必须手动调整按钮的大小。