Tkinter - Button Overrelief

Fuzzyman fuzzyman at gmail.com
Tue Jun 27 18:02:37 EDT 2006


Eric Brunel wrote:
> On Tue, 27 Jun 2006 14:06:05 +0200, Fuzzyman <fuzzyman at gmail.com> 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+-'])"




More information about the Python-list mailing list