mhwh
mhwh

Reputation: 490

tkinter unknown option "pyimage"

I am running into a similar problem as described here: Why in the world does Python's Tkinter break using canvas.create_image?

But I am using canvas.creat_image alredy. Please have a look at my code.

import tkinter as tk

root = tk.Tk()

img = tk.PhotoImage(file="image.gif")

can= tk.Canvas(root, width=600, height=600)
can.create_image(400, 400, img)
can.pack()

root.mainloop()

The error message I get is: TclError: unknown option "pyimage5" where the number after pyimage increments by one each time I run it.
The image itself works fine if I run the code below it displays fine...

import tkinter as tk

root = tk.Tk()

img = tk.PhotoImage(file="image.gif")

img_label = tk.Label(image=img)
img_label.pack()

root.mainloop()

Please also see the system specifcations here.

 import IPython
print(IPython.sys_info())
{'commit_hash': '5a894b9',
 'commit_source': 'installation',
 'default_encoding': 'cp1252',
 'ipython_path': 'C:\\ProgramData\\Anaconda3\\lib\\site-packages\\IPython',
 'ipython_version': '5.3.0',
 'os_name': 'nt',
 'platform': 'Windows-10-10.0.15063-SP0',
 'sys_executable': 'C:\\ProgramData\\Anaconda3\\pythonw.exe',
 'sys_platform': 'win32',
 'sys_version': '3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, '
                '13:25:24) [MSC v.1900 64 bit (AMD64)]'}

Upvotes: 0

Views: 1449

Answers (1)

Mike - SMT
Mike - SMT

Reputation: 15226

Your problem is this line:

can.create_image(400, 400, img)

Change it to this:

can.create_image(400, 400, image = img)

Upvotes: 2

Related Questions