FAQ
Hello all,

I have some Tkinter buttons that display images. I would like to change
these to 'active' images when the mouse is over the button.

I see that the button widget can take an 'overrelief' argument in the
constructor. What values can this take ?

Also - can anyone provide an example of using the equivalent of a
'mouseover' event to change the image used by a button in Tkinter ? I'm
afraid google has not helped me much here.

Much Appreciated,


Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

Search Discussions

  • Eric Brunel at Jun 27, 2006 at 1:40 pm

    On Tue, 27 Jun 2006 14:06:05 +0200, Fuzzyman wrote:

    Hello all,

    I have some Tkinter buttons that display images. I would like to change
    these to 'active' images when the mouse is over the button.

    I see that the button widget can take an 'overrelief' argument in the
    constructor. What values can this take ?
    The same as the 'relief' option, i.e the ones described here:
    http://www.tcl.tk/man/tcl8.4/TkCmd/options.htm#M-relief

    Note that Tkinter contains symbolic constants for these values: 'raised'
    is Tkinter.RAISED, 'flat' is Tkinter.FLAT, and so on.
    Also - can anyone provide an example of using the equivalent of a
    'mouseover' event to change the image used by a button in Tkinter ? I'm
    afraid google has not helped me much here.
    The events you're after are '<Enter>' and '<Leave>'; see here:
    http://www.tcl.tk/man/tcl8.3/TkCmd/bind.htm#M7

    Here is an example showing how to change the button text (changing the
    image is similar):

    --------------------------------
    from Tkinter import *

    root = Tk()

    b = Button(root, width=8, text='foo')
    b.pack()

    def enterB(event):
    b.configure(text='bar')

    def leaveB(event):
    b.configure(text='foo')

    b.bind('<Enter>', enterB)
    b.bind('<Leave>', leaveB)

    root.mainloop()
    --------------------------------

    HTH
    --
    python -c "print ''.join([chr(154 - ord(c)) for c in
    'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
  • Fuzzyman at Jun 27, 2006 at 10:02 pm

    Eric Brunel wrote:
    On Tue, 27 Jun 2006 14:06:05 +0200, Fuzzyman wrote:

    Hello all,

    I have some Tkinter buttons that display images. I would like to change
    these to 'active' images when the mouse is over the button.

    I see that the button widget can take an 'overrelief' argument in the
    constructor. What values can this take ?
    The same as the 'relief' option, i.e the ones described here:
    http://www.tcl.tk/man/tcl8.4/TkCmd/options.htm#M-relief

    Note that Tkinter contains symbolic constants for these values: 'raised'
    is Tkinter.RAISED, 'flat' is Tkinter.FLAT, and so on.
    Cool, I'll have to look into this and see how they look. Thanks.
    Also - can anyone provide an example of using the equivalent of a
    'mouseover' event to change the image used by a button in Tkinter ? I'm
    afraid google has not helped me much here.
    The events you're after are '<Enter>' and '<Leave>'; see here:
    http://www.tcl.tk/man/tcl8.3/TkCmd/bind.htm#M7

    Here is an example showing how to change the button text (changing the
    image is similar):

    --------------------------------
    from Tkinter import *

    root = Tk()

    b = Button(root, width=8, text='foo')
    b.pack()

    def enterB(event):
    b.configure(text='bar')

    def leaveB(event):
    b.configure(text='foo')

    b.bind('<Enter>', enterB)
    b.bind('<Leave>', leaveB)

    root.mainloop()
    That works like a charm, great.

    Much Appreciated

    Fuzzyman
    http://www.voidspace.org.uk/python/index.shtml
    --------------------------------

    HTH
    --
    python -c "print ''.join([chr(154 - ord(c)) for c in
    'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 27, '06 at 12:06p
activeJun 27, '06 at 10:02p
posts3
users2
websitepython.org

2 users in discussion

Fuzzyman: 2 posts Eric Brunel: 1 post

People

Translate

site design / logo © 2022 Grokbase