Python Forum

Full Version: Help: Enlarge image on hover
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All!

First of all I am new to this forum as well as to Python. As an example, I am trying to program a very simple UI using Tkinter with a clickable image. I would like to be able to enlarge the image when hovering on it with the cursor. I already tried quite a few examples online but unfortunately to no avail. Does anyone have any ideas on how to do so?

Just to know: I am using Python 2.7

Many thanks in advance!

The code:

from Tkinter import *
from Tkinter import PhotoImage


class RedButton(Button):

def __init__(self, parent, **options):
Button.__init__(self, parent, **options)
self['bg'] = 'red'


window = Tk()
window.geometry('1280x600')

RedButton(window, text="Button #1").pack()


def callback():
print "click!"


photo = PhotoImage(file='notification.gif') # type: PhotoImage
b = Button(window, image=photo, command=callback, height=375, width=289, compound=LEFT)
b.pack()

mainloop()
Please put your code in Python code tags. You can find help here.