May-10-2021, 04:13 PM
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()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags