Tkinter - Button Overrelief

F

Fuzzyman

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
 
E

Eric Brunel

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

Fuzzyman

Eric said:
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.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top