Jul-08-2021, 07:04 PM
My 2 cents - Using deanhystad's example with state and imagedisabled. Replaced the after with a button.
#! /usr/bin/env python3 import tkinter as tk root = tk.Tk() canvas = tk.Canvas(root, height=120, width=100) canvas.pack() def toggle(): if canvas.itemconfigure(x)['state'][4] == tk.DISABLED: canvas.itemconfigure(x, state=tk.NORMAL) btn['text'] = 'Turn off' btn['fg'] = 'red' else: canvas.itemconfigure(x, state=tk.DISABLED) btn['text'] = 'Turn on' btn['fg'] = 'green' on = tk.PhotoImage(file='on.png') off = tk.PhotoImage(file='off.png') x = canvas.create_image(50, 50, image=on, disabledimage=off) btn = tk.Button(root, text='Turn off', fg='red', command=toggle) btn.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