using itertools.cycle() to create a Tkinter ToogleUpDownImageButton
tested with Python27 by vegaseat 01aug2014
import itertools as it
import Tkinter as tk
import tkinter as tk
# images are of an up and down button
# pick GIF images you have in the working directory or give full path
self.image_up = tk.PhotoImage(file='btn_up.gif')
self.image_down = tk.PhotoImage(file='btn_down.gif')
self.images = it.cycle([self.image_down, self.image_up])
self.button = tk.Button(self, image=self.image_up, command=self.toggle)
toggle between up and down button images
self.button['image'] = next(self.images)
app = ToogleUpDownImageButton()
Are you able to help answer this sponsored question?
Questions asked by members who have earned a lot of community kudos are featured in order to give back and encourage quality replies.