Advertisement
furas

Tkinter - PhotoImage in module

Jul 22nd, 2018
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. # --- other.py ---
  2.  
  3. import tkinter as tk
  4. import os
  5.  
  6. HOME = os.path.dirname(os.path.abspath(sys.argv[0]))
  7.  
  8. def load_images():
  9.     return {
  10.         'blanc': tk.PhotoImage(file=os.path.join(HOME, "blanc.gif")),
  11.         #'blanc': tk.PhotoImage(file=os.path.join(HOME, "images", "blanc.gif")),
  12.     }
  13.  
  14. # --- main.py ---
  15.  
  16. import tkinter as tk
  17. import other
  18.  
  19. #images = other.load_images() #Too early to create image
  20.  
  21. root = tk.Tk()
  22.  
  23. images = load_images() # OK
  24.  
  25. l = tk.Label(root, image=images['blanc'])
  26. l.pack()
  27.  
  28. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement