FAQ
Is there any way to highlight, bold or change the color of one word
in a variable to be displayed on a Tkinter GUI?

Like:

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

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

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080918/b0aac7a3/attachment.htm>

Search Discussions

  • April Lekin at Sep 18, 2008 at 5:07 pm
    Is there any way to highlight, bold or change the color of one word
    in a variable to be displayed on a Tkinter GUI?

    Like:

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

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

    Thanks
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20080918/c5c5659f/attachment.htm>
  • Guilherme Polo at Sep 18, 2008 at 5:15 pm

    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()



    --
    -- Guilherme H. Polo Goncalves

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 18, '08 at 4:06p
activeSep 18, '08 at 5:15p
posts3
users2
websitepython.org

2 users in discussion

April Lekin: 2 posts Guilherme Polo: 1 post

People

Translate

site design / logo © 2022 Grokbase