Ich hab folgendes Problem ich möchte in meinen Code ein Bild einfügen. Doch es funktioniert nicht. Ich bekomme nur eine Fehlermeldung. Ich weiß nicht wie ich das lösen kann.
Code: Alles auswählen
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
return self.func(*args)
File "C:\Users\--------\Desktop\Adressbuch\adressbuch.py", line 59, in neuer_kontakt
self.label = tk.Label(self.win, image=self.image1, width=200, height=266)
File "C:\Python32\lib\tkinter\__init__.py", line 2459, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Python32\lib\tkinter\__init__.py", line 1958, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage1" doesn't exist
Code: Alles auswählen
import tkinter as tk
from tkinter import ttk
class Adressbuch:
def __init__(self):
self.main = tk.Tk()
self.main.title('Adressbuch')
self.main.geometry('500x400')
self.main.grid_rowconfigure(0, weight=1)
self.frame = tk.Frame(self.main).grid(column=0)
self.cnv = tk.Canvas(self.frame)
self.cnv.grid(row=0, column=2, sticky='ns')
self.vScroll = ttk.Scrollbar(self.frame, orient='vertical',
command=self.cnv.yview)
self.vScroll.grid(row=0, column=1, sticky='ns')
self.cnv.configure(yscrollcommand=self.vScroll.set)
self.frm = tk.Frame(self.cnv)
self.cnv.create_window(0, 0, window=self.frm, anchor='nw')
self.mBar = tk.Menu(self.main, tearoff=0)
self.mFile = tk.Menu(self.mBar, tearoff=0)
self.mFile.add_command(label="Neuer Kontakt", command=self.neuer_kontakt)
self.mBar.add_cascade(label="Adressen", menu=self.mFile)
self.main["menu"] = self.mBar
self.frm.update_idletasks()
self.cnv.configure(scrollregion=(0, 0, 0, self.frm.winfo_height()))
self.main.mainloop()
def neuer_kontakt(self):
self.image1 = tk.PhotoImage(file="test.gif")
self.win = tk.Tk()
self.win.title('Neuer Kontakt')
#self.win.geometry('500x250')
self.frame = tk.Frame(self.win)
self.frame.pack(side='left', anchor='n')
self.labels = ('','',('Vorname'), ('Nachname'), ('Geburtsdatum'),
('Handy-Nr.'), ('E-Mail'), 'Telefon', 'Straße', 'PLZ/Ort')
self.label_control = list()
self.e_control = list()
for row, text in enumerate(self.labels):
ttk.Label(self.frame, text = 'Neuer Kontakt').grid(column=1, row=0, rowspan=2)
label = tk.Label(self.frame, text=text, width=12, anchor='w')
label.grid(column=0, row=row)
self.label_control.append(label)
for row in range(2,10):
self.e = ttk.Entry(self.frame, width=20).grid(column=1, row=row)
self.e_control.append(self.e)
self.label2 = tk.Label(self.win, image=self.image1, width=200, height=266)
self.label2.pack()
self.win.mainloop()
app = Adressbuch()
Gruß Tom