May-22-2018, 09:48 AM
(This post was last modified: May-22-2018, 09:48 AM by morganruben.)
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()
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()