SHARE
TWEET

Tkinter - PhotoImage in module

furas Jul 22nd, 2018 (edited) 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top