furas

Tkinter - PhotoImage in module

Jul 22nd, 2018
106
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×