473,480 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 8150
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
6990
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
3990
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
3216
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
6069
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
4518
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
3575
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
3590
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
5200
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
3898
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
7037
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
7080
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...
1
6735
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5326
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4770
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
176
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.