Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Tkinter Bold Text

Reply
Thread Tools

Re: Tkinter Bold Text

 
 
Guilherme Polo
Guest
Posts: n/a
 
      09-18-2008
On Thu, Sep 18, 2008 at 1:06 PM, April Lekin <> wrote:
> Is there any way to highlight, bold or change the color of one word in a
> variable to be displayed on a Tkinter GUI?


Yes.

>
> Like:
>
> material = "Plastic"
> introVal = "This report describes the construction of the %s." % (material)
>


You could separate them in two labels (if you are using labels), or
apply a different tag if you are using a Text widget.

> this is what I want:
> This report describes the construction of the Plastic.
> Plastic is Bold or Blue or Green
>


Changing the color is easier, you only change the foreground option.
Changing to bold may not work for you, because depending on your Tk
version and platform it will already be bold, so you won't notice
anything. There is also a "catch" in changing text to bold, if you
only set the text option of your Label to "-weight bold" it will
probably get you a bold text, but with a different font than the one
being used by other Labels.

Now, something you could use as a base:

import Tkinter
import tkFont

root = Tkinter.Tk()

otherpart = Tkinter.Label(text="some text here")
special = Tkinter.Label(text="special", foreground='blue')
otherpart.pack(side='left')
special.pack(side='left')

f = tkFont.Font(font=otherpart['font'])
f['weight'] = 'bold'
f['underline'] = True

special['font'] = f.name

root.mainloop()


> Thanks
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>




--
-- Guilherme H. Polo Goncalves
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to add automatically bold mark-up to text in detailsview in editmode? Tony ASP .Net 0 10-13-2008 01:23 PM
Bold Text In Datgrid Row If strResult="Purchased" Jonathan ASP .Net 7 03-18-2008 01:53 AM
Firefox - Rich Text Editing: Cannot do a text bold...? deostroll Javascript 1 01-11-2008 09:49 PM
Office Word problem with BOLD option on selected text nico Computer Support 2 01-10-2004 11:18 AM
[DOPEY NEWBIE] Why doesn't Mozilla display text in bold? marked HTML 7 09-10-2003 02:10 AM



Advertisments