Python Forum
[Tkinter] Glow text of clickable object on hover with transition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Glow text of clickable object on hover with transition
#6
Thought I would add an image version.


#! /usr/bin/env python3

import tkinter as tk

def on_enter(e):
    img = tk.PhotoImage(file='enter.png')
    btn['image'] = img
    img.img = img
    label['text'] = 'Enter button area.'

def on_exit(e):
    img = tk.PhotoImage(file='default.png')
    btn['image'] = img
    img.img = img
    label['text'] = 'Exit button area'

def on_press(e):
    img = tk.PhotoImage(file='press.png')
    btn['image'] = img
    img.img = img
    label['text'] = 'Pressed the button'

def on_release(e):
    img = tk.PhotoImage(file='default.png')
    btn['image'] = img
    img.img = img
    label['text'] = 'Button was released'

root = tk.Tk()
root.geometry('+400+300')
img = tk.PhotoImage(file='default.png')
btn = tk.Button(image=img)
btn.pack()
img.img = img
btn.bind('<Enter>', on_enter)
btn.bind('<Leave>', on_exit)
btn.bind('<Button-1>', on_press)
btn.bind('<ButtonRelease-1>', on_release)

label = tk.Label(None, text='', bg='ivory', fg='purple', width=50, height=15)
label.pack()

root.mainloop()
andy likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: Glow text of clickable object on hover with transition - by menator01 - May-10-2021, 04:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] Hover over highlighted text and open popup window DrakeSoft 2 1,693 Oct-29-2022, 04:30 PM
Last Post: DrakeSoft
  [PyQt] Determining the format attributes on text in a QTextEdit object DrakeSoft 7 3,807 Apr-18-2022, 06:40 PM
Last Post: DrakeSoft
  [PyQt] AttributeError: 'NoneType' object has no attribute 'text' speedev 9 11,821 Sep-25-2021, 06:14 PM
Last Post: Axel_Erfurt
  [Tkinter] Clickable Rectangles Tkinter Canvas MrTim 4 9,260 May-11-2021, 10:01 PM
Last Post: MrTim
  [Tkinter] Hover event DT2000 9 7,640 Apr-19-2020, 05:51 AM
Last Post: DT2000
  Making text clickable with binding DT2000 10 5,403 Apr-02-2020, 10:11 PM
Last Post: DT2000
  [PyQt] Ubuntu Taskbar icon shows title as "Unknown" while hover davidmuni 3 3,871 Jan-28-2020, 01:13 PM
Last Post: davidmuni
  Help: Enlarge image on hover morganruben 1 3,308 May-22-2018, 10:08 AM
Last Post: j.crater
  (pyQt/pySide)setStyleSheet(border…) makes QPushButton not clickable in Maya vladlenPy 0 4,841 Apr-15-2018, 12:41 PM
Last Post: vladlenPy
  pyqt clickable pushbutton problem pythonck 1 7,791 Dec-12-2017, 03:38 PM
Last Post: pythonck

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020