Guest User

Untitled

a guest
Oct 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import Tkinter as tk
  2. from PIL import Image, ImageTk
  3. import glob, os
  4.  
  5.  
  6. # image types we're gonna check for
  7. valid_images = [".jpg",".gif",".png",".tga",".jpeg",".bmp",".webm"]
  8.  
  9. imageList = []
  10.  
  11. curImg = 0
  12.  
  13. #find images in directory
  14. for x in valid_images:
  15. for file in glob.glob("*" + x):
  16. imageList.append(file)
  17.  
  18. print(imageList)
  19.  
  20. print len(imageList)
  21.  
  22. #This creates the main window of an application
  23. window = tk.Tk()
  24. window.title("Join")
  25.  
  26. window.configure(background='grey')
  27.  
  28.  
  29. path = "sample.png"
  30. img = ImageTk.PhotoImage(Image.open(path))
  31. window.geometry(str(img.width()) + "x" + str(img.height()))
  32. #Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
  33.  
  34. #The Label widget is a standard Tkinter widget used to display a text or image on the screen.
  35. panel = tk.Label(window, image = img)
  36.  
  37. #The Pack geometry manager packs widgets in rows or columns.
  38. panel.pack(side = "bottom", fill = "both", expand = "yes")
  39.  
  40. def SetImg(newPath):
  41. global img
  42. global panel
  43. global window
  44. img = ImageTk.PhotoImage(Image.open(newPath))
  45. panel.configure(image=img)
  46. window.geometry(str(img.width()) + "x" + str(img.height()))
  47. window.update()
  48.  
  49. def ShiftCurImg(amount):
  50. global curImg
  51. curImg = (curImg + amount) % (len(imageList))
  52. print 'Attempting to access image index: ' + str(curImg)
  53. SetImg(imageList[curImg])
  54.  
  55. #SetImg(path)
  56.  
  57. #create keypress event method.
  58. def key(event):
  59. if event.keysym == 'Left':
  60. ShiftCurImg(-1)
  61. elif event.keysym == 'Right':
  62. ShiftCurImg(1)
  63.  
  64. #Start the GUI
  65.  
  66. window.bind_all('<Key>', key)
  67. window.mainloop()
Add Comment
Please, Sign In to add comment