Skip to content

Instantly share code, notes, and snippets.

@dheaney
Created June 16, 2018 04:35
Show Gist options
  • Save dheaney/be09e8ed2e53e1fde30e7962ba431150 to your computer and use it in GitHub Desktop.
Save dheaney/be09e8ed2e53e1fde30e7962ba431150 to your computer and use it in GitHub Desktop.
from Tkinter import *
import glob
class MyWindow(object):
def __init__(self):
self.label = None
self.root = Tk()
self.i = 0
self.files = glob.glob('./*.png') + glob.glob('./*.jpg') + glob.glob('./*.jpeg')
self.left = Button(self.root, text="Left", command=self.lclick)
self.right = Button(self.root, text="Right", command=self.rclick)
self.frame = Frame(self.root, width=500, height=500)
self.left.pack()
self.right.pack()
self.frame.pack()
self.update()
self.root.mainloop()
def lclick(self):
self.i = self.i + 1
if self.i >= len(self.files):
self.i = 0
self.update()
def rclick(self):
self.i = self.i - 1
if self.i <= 0:
self.i = len(self.files) - 1
self.update()
def update(self):
if self.label:
self.label.destroy()
self.photo = PhotoImage(file=self.files[self.i])
self.label = Label(self.frame, image=self.photo, width=500, height=500)
self.label.pack();
m = MyWindow()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment