473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Tkinter - Button Overrelief

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

Jun 27 '06 #1
2 8139
On Tue, 27 Jun 2006 14:06:05 +0200, Fuzzyman <fu******@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.
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+-'])"
Jun 27 '06 #2

Eric Brunel wrote:
On Tue, 27 Jun 2006 14:06:05 +0200, Fuzzyman <fu******@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+-'])"


Jun 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: srijit | last post by:
Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter...
2
by: mksql | last post by:
New to Tkinter. Initially, I had some code that was executing button commands at creation, rather than waiting for user action. Some research here gave me a solution, but I am not sure why the...
2
by: Paul A. Wilson | last post by:
I'm new to Tkinter programming and am having trouble creating a reusable button bar... I want to be able to feed my class a dictionary of button names and function names, which the class will make....
6
by: Elaine Jackson | last post by:
I've got a script where a button gets pushed over and over: to cut down on the carpal tunnel syndrome I'd like to have the button respond to presses of the Enter key as well as mouse clicks; can...
7
by: Harlin Seritt | last post by:
I was looking at the Tcl/Tk sourceforge page and found that there were a couple of new widgets being produced for Tcl 8.5. Does anyone know if there are any Tkinter wrappers somewhere? thanks, ...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
3
by: dwelch91 | last post by:
I'm trying unsuccessfully to do something in Tk that I though would be easy. After Googling this all day, I think I need some help. I am admittedly very novice with Tk (I started with it...
1
by: yvesd | last post by:
hello i want to intercept tkinter python system events like wm_delete_window and if possible for any window, but the newest code I've produced give me an error : Traceback (most recent call...
3
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.