简体   繁体   中英

Tkinter: Use different font (color, size, etc.) for the text within the same button?

I have a very specific question.

I have a tkinter button. Each time I click it I get a pop-up window with an Entry box. Enter a text and press enter I can change the text of this button. I can do it as many time as the as I want.

Now the question is: can I make the button text to have different color and font size? Say the original button text is "btn 1". The first time I click it. The text becomes "btn 1\\nFirstClick". The second time the text is ""btn 1\\nFirstClick\\nSecondClick".

I have all the code worked out as I wanted. But now I want "FirstClick" to be in Red and "SecondClick" to be in Green".

Is that possible? I googled and can't find the answer.

You cannot use multiple fonts or colors in a single button. Your only option would be to create a custom widget that looks and behaves like a button, but which is implemented with a Text or Canvas widget. Those two widgets allow you to use multiple colors and fonts at the same time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM