1

I have the following code:

from tkinter import *
from PIL import Image, ImageTk

class Imageviewer:

    def __init__(self, master):
        frame = Frame(master)
        frame.pack()

        self.previousButton = Button(frame, text = "Previous",
                                     command = lambda:print("hello2"))
        self.previousButton.pack()

        self.nextButton = Button(frame, text = "Next Image",
                                 command = lambda:print("Sziavagyok"))
        self.nextButton.pack()

        photo = Image.open('./kepek/hello(1).png')
        imag = ImageTk.PhotoImage(photo)
        self.Kep = Label(master, image = imag)
        self.Kep.image = imag
        self.Kep.pack()


    def printMessage(self):
        print("Helloka")

root = Tk()
viewer = Imageviewer(root)
root.mainloop()

When I try to run this, I get this error:

Traceback (most recent call last):
  File "C:/Users/gergo/PycharmProjects/untitled/hello.py", line 34, in <module>
    viewer = imag.Imageviewer(root)
  File "C:\Users\gergo\PycharmProjects\untitled\imageviewer.py", line 18, in __init__
    self.Kep = Label(frame, image = imag)
  File "C:\Users\gergo\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2766, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
  File "C:\Users\gergo\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2299, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage10" doesn't exist

I tried the way it is written everywhere, but still doesn't work... any help?

martineau
  • 119,623
  • 25
  • 170
  • 301

0 Answers0