Click here to Skip to main content
15,070,680 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey, I'm trying to learn python and I have a problem.
from tkinter import *
from PIL import ImageTk, ImageTk

root = Tk()
root.title("Learn to Code at Codemy")
root.iconbitmap("C:/Py Python/gui/forpyt/favicon.ico")
my_img = ImageTk.PhotoImage("C:/Users/Vlad/Desktop/python/pytt.png"))
my_label = Label(image = my_img)

button_quit = Button(root, text = "Exit Program", command = root.quit)

What I have tried:

This program should show me a box with a picture inside it, but it doesn't. It's a problem with "my_img", it shows me "Exception has occurred: AttributeError
type object 'Image' has no attribute 'open'" I don't know what to do to solve the issue. I've installed PIL, i have everything, but it doesn't work
Updated 23-Dec-20 6:06am

For basic syntax errors you should always check the documentation first: ImageTk Module — Pillow (PIL Fork) 8.0.1 documentation[^]
my_img = ImageTk.PhotoImage("C:/Users/Vlad/Desktop/python/pytt.png"))
my_img = ImageTk.PhotoImage(file="C:/Users/Vlad/Desktop/python/pytt.png")
see Basics For Displaying Image In Tkinter Python[^]
Vlad Țepeș ツ 23-Dec-20 13:30pm
Its working but it's not showing me the "Exit program" button.
I find another solution, i did this:
from PIL import ImageTk
from PIL import Image as PilImage

and at my_img
my_img = ImageTk.PhotoImage(
But again, it doesn't show me the "Exit program" Button. What can i do ?
Patrice T 23-Dec-20 20:47pm
If you want other people to pay attention to this, update your question.
Use Improve question to update your question.
Vlad Țepeș ツ 24-Dec-20 11:39am
I solved it, i just changed the photo resolution, thx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900