Hi all...
I create an interface tkinter, with python3. (3.6.2 on OpenBSD)
My folder:
the script 'yup.tk.py' call script 'window_about.py'.
into script 'yup.tk.py', i use module PIL to insert image into tk.Label, as:
But, into the script 'window_about.py', this code not run, with error:
I have the same error if i replace, into 'window_about.py', by this code:
I create an interface tkinter, with python3. (3.6.2 on OpenBSD)
My folder:
Quote:yup.tk.py
/modules/__init__.py (empty)
/modules/window_about.py
the script 'yup.tk.py' call script 'window_about.py'.
into script 'yup.tk.py', i use module PIL to insert image into tk.Label, as:
import tkinter as tk import tkinter.ttk as ttk import PIL.Image as pimg import PIL.ImageTk as pimgtk NAME = "MyAPP" class Gui(tk.Tk): '''Gui tkinter''' def __init__(self, parent): tk.Tk.__init__(self, parent) self.parent = parent self.dir = os.path.dirname(os.path.abspath(sys.argv[0])) self.icon = os.path.join(self.dir, 'img', 'Logo.xbm') self.img_logo = None self.logo = os.path.join(self.dir, 'img', 'Logo.png') self.initialize() def about(self): '''Displaying a window about''' from modules.window_about import gui init = { 'DESCR': DESCR, 'dir': self.dir, 'icon': self.icon, 'img_logo': self.img_logo, 'logo': self.logo, 'NAME': NAME, } about = gui(None, init) about.title(NAME) about.mainloop() def initialize(self): '''Initialize window''' self.grid() (...) self.menu() self.ui() def menu(self): "Displaying menubar" menubar = tk.Menu(self) menuFile = tk.Menu(menubar, tearoff=0) menuFile.add_command(label="Créer", command=self.alert) menuFile.add_separator() menuFile.add_command(label="Quitter", underline=0, command=self.byebye, accelerator="Ctrl+Q") menubar.add_cascade(label="Fichier", underline=0, menu=menuFile) menuHelp = tk.Menu(menubar, tearoff=0) menuHelp.add_command(label="À-propos", underline=0, command=self.about) menubar.add_cascade(label="Aide", underline=0, menu=menuHelp) self.config(menu=menubar) def ui(self): '''Displaying UI''' # Frame for service informations self.frm_service = ttk.Frame(self) self.frm_service.grid(row=7, column=3) ## Add an image logo logo_open = pimg.open(self.logo) self.img_logo = pimgtk.PhotoImage(logo_open) print(f'{self.img_logo}') img_service = ttk.Label(self.frm_service, image=self.img_logo) img_service.grid(row=0, column=0, rowspan=2) (...)The img logo (self.img_logo) is correctly displaying into the gui.
But, into the script 'window_about.py', this code not run, with error:
Error:pyimage2
self.DESCR: Yet Uploader Pixxie.py
self.dir: ~/YUP.py
self.icon: ~/YUP.py/img/Logo.xbm
self.img_logo: pyimage2
self.logo: ~/YUP.py/img/Logo.png
self.NAME: YUPixxie
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/local/lib/python3.6/tkinter/__init__.py", line 1699, in __call__
return self.func(*args)
File "~/YUP.py/yup.tk.py", line 431, in about
about = gui(None, init)
File "~/YUP.py/modules/window_about.py", line 33, in __init__
self.initialize()
File "~/YUP.py/modules/window_about.py", line 40, in initialize
self.ui()
File "~/YUP.py/modules/window_about.py", line 64, in ui
img_service = ttk.Label(frm_service, image=self.img_logo)
File "/usr/local/lib/python3.6/tkinter/ttk.py", line 761, in __init__
Widget.__init__(self, master, "ttk::label", kw)
File "/usr/local/lib/python3.6/tkinter/ttk.py", line 559, in __init__
tkinter.Widget.__init__(self, master, widgetname, kw=kw)
File "/usr/local/lib/python3.6/tkinter/__init__.py", line 2293, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage2" doesn't exist
The python3 code into 'window_about.py':import tkinter as tk import tkinter.ttk as ttk import PIL.Image as pimg import PIL.ImageTk as pimgtk class gui(tk.Tk): ''' Display a GUI for window about''' def __init__(self, parent, init): tk.Tk.__init__(self, parent) self.parent = parent # initialise self for i in init: setattr(self, i, init[i]) print(f'self.{i}: {init[i]}') self.initialize() (...) def initialize(self): '''Initialize window''' self.grid() (...) self.ui() (...) def ui(self): '''Displaying UI''' # Frame for service informations frm_service = ttk.Frame(self) frm_service.grid(row=7, column=1) ## Add an image logo img_service = ttk.Label(frm_service, image=self.img_logo) img_service.grid(row=0, column=0, rowspan=2) (...)why 'self.img_logo' - who is PhotoImage declaration - not run into 'window_about.py'.
I have the same error if i replace, into 'window_about.py', by this code:
(...) logo_open = pimg.open(self.logo) img_logo = pimgtk.PhotoImage(logo_open) print(f'{img_logo}') img_service = ttk.Label(frm_service, image=img_logo) img_service.grid(row=0, column=0, rowspan=2) (...)