469,955 Members | 2,606 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,955 developers. It's quick & easy.

Issue of tkinter

i cannot add picture in toplevel new window after trying 40 times
3 Weeks Ago #1
1 10360
1 Bit
Every widget needs parent. If you don't use it then tkinter assigs widget to main window.

And you have this problem in Label(image = poke) because you forgot win in

pika = Label(win, image=poke)
This is why you see rectangle in main window instead of toplevel window.

Second: There is bug in PhotoImage. Garbage Collector removes it from memory when it is created in function and assigned to local variable. And then you can see empty image.

You have to assign PhotoImage to global variable or assign to other widget in function.

Popular solution with assigning to other widget:

poke = PhotoImage(file = "pika.gif")
pika = Label(win, image=poke)
pika.photo = poke # <-- assign PhotoImage to other widget too
Python Course in Pune
1 Week Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by mksql | last post: by
5 posts views Thread by Ben Kovitz | last post: by
7 posts views Thread by krishnakant Mane | last post: by
44 posts views Thread by bg_ie | last post: by
reply views Thread by wolfonenet | last post: by
8 posts views Thread by karthikbalaguru | last post: by
reply views Thread by Guilherme Polo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.