471,354 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Why Image doesnt appear in a Tkinter child frame?

Elias Alhanatis
Hello everybody!!

I would like some help with the following problem:
I have the following piece of code:


Expand|Select|Wrap|Line Numbers
  1.  
  2. from Tkinter import *
  3. root = Tk()
  4. menuframe=Frame(root,height="1c",width="30c",bg="#d5ab6c",bd=2,relief=RAISED)
  5. menuframe.pack(expand=NO,side=TOP,fill=BOTH)
  6. mainframe=Frame(root,height="19.8c",width="30c",bg="#d5ab3c",bd=2,relief=RAISED)
  7. mainframe.pack()#expand=NO,side=TOP,fill=BOTH)
  8. CN=Canvas(mainframe,height="19.8c",width="30c",bg="#d5ab3c")
  9. images="C:/Python25/pic.GIF"
  10. photo1=PhotoImage(file=images)
  11. CN.create_image("15c","9.9c",image=photo1)
  12. CN.pack()
  13.  
  14. mBar = Frame(menuframe, relief=RAISED, borderwidth=2)
  15. mBar.pack(fill=X,side=LEFT)
  16.  
  17. ArxBtn = makeArxiaMenu()
  18. KinBtn = makeKiniseisMenu()
  19. EktBtn = makeEktyposeisMenu()
  20. VoiBtn = makeVoithitikaMenu()
  21. RytBtn = makeRythmiseisMenu()
  22. EpiBtn = makeEpikoinoniesMenu()
  23. mBar.tk_menuBar(ArxBtn,KinBtn,EktBtn,VoiBtn,RytBtn,EpiBtn)
  24.  
  25.  
  26. root.title('Window App by Elias')
  27. root.geometry("1142x800")
  28. root.mainloop()
  29.  
  30.  
Then , from the buttons of the menu , i can "destroy" the mainframe and recreate it as it should be for the coresponding function.
Here is an example for the code i use in one of the functions:

Expand|Select|Wrap|Line Numbers
  1.  
  2. def Polites():
  3.     global mainframe
  4.     mainframe.destroy()
  5.     mainframe=Frame(root,height="19.8c",width="30c",bd=4,relief=RAISED)
  6.     mainframe.pack(anchor=SW)
  7.  
  8.     Pict=Canvas(mainframe,height="19.8c",width="30c",bg="#d5ab3c")
  9.     images="C:/Python25/maria.GIF"
  10.     photo1=PhotoImage(file=images)
  11.     Pict.create_image("15c","9.9c",image=photo1)
  12.     Pict.grid()
  13.  
  14.  
The problem is that the program "refuses" to display any image in the child
widgets of mainframe ( i tried through Canvas and Label ).
The strange things are :
1)All works fine in the initial mainframe ( the picture is displayed ) but in the
next mainframe construction ...no Images.
2) the space of the widget is actually there , and the widgets are responsive for text inserts etc... BUT , no Images.

I am working on Windows Vista , Pyhton 2.5

I would be gratefull for any help on this....

Thank you all in advance...

Elias
Oct 28 '07 #1
4 2181
bartonc
6,596 Expert 4TB
Right off the bat, I notice that you use different geometry managers.
widget.grid() and widget.pack() are not equivalent. NOTE: The geometry managers may not be mixed in a single frame.

If I get some time later, I'll try running you program on my system.

In case you haven't found the Tkinter docs yet: An Introduction to Tkinter.

You'll notice that they are quite old. Generally, Tkinter is not getting much support these days.

Hope that helps,
Barton
Oct 28 '07 #2
Dear Bartonc ,

I thank you for your quick reply to my question.
I know that mixing the layout managers is messy , but i dont think the
problem is there. Here is a simpler example of code i tried which again ,
refuses to draw the images....

Expand|Select|Wrap|Line Numbers
  1.  
  2. from Tkinter import *
  3.  
  4.  
  5. def f1():
  6.     mainframe=Frame(root)
  7.     mainframe.pack()
  8.     CN=Canvas(mainframe,height="9.8c",width="15c",bg="#d5ab3c")
  9.     images="C:/Python25/Bother/3.GIF"
  10.     photo1=PhotoImage(file=images)
  11.     CN.create_image("7.55c","4.9c",image=photo1)
  12.     CN.pack()
  13.  
  14.  
  15. def f2():
  16.     mainframe2=Frame(root)
  17.     mainframe2.pack()
  18.     CN=Canvas(mainframe2,height="9.8c",width="15c",bg="#d5ab3c")
  19.     images="C:/Python25/GIFS/5bl.103b.GIF"
  20.     photo1=PhotoImage(file=images)
  21.     CN.create_image("7.5c","4.9c",image=photo1)
  22.     CN.pack()
  23.  
  24. root=Tk()
  25. f1()
  26. f2()
  27. root.mainloop()
  28.  
  29.  
It seems like i am missing something basic here.....

Thanks again for your time... :)

Elias
Oct 28 '07 #3
bartonc
6,596 Expert 4TB
Dear Bartonc ,

I thank you for your quick reply to my question.
I know that mixing the layout managers is messy , but i dont think the
problem is there.

Thanks again for your time... :)

Elias
I wasn't suggesting that mixing GMs was the problem, simply warning you about the conflict. What I suggest is that this:
Expand|Select|Wrap|Line Numbers
  1.  
  2. def Polites():
  3.     global mainframe
  4.     mainframe.destroy()
  5.     mainframe=Frame(root,height="19.8c",width="30c",bd=4,relief=RAISED)
  6.     mainframe.pack(anchor=SW)
  7.  
  8.     Pict=Canvas(mainframe,height="19.8c",width="30c",bg="#d5ab3c")
  9.     images="C:/Python25/maria.GIF"
  10.     photo1=PhotoImage(file=images)
  11.     Pict.create_image("15c","9.9c",image=photo1)
  12.     Pict.grid()
  13.  
  14.  
(as you said) works because it uses widget.grid() instead of .pack().
Oct 28 '07 #4
Just to close this thread ( in case anyone wondered what was the problem..):

The absense of the picture was due to a bug in PIL , which is fixed
if you append your images to a list, so the program "keeps them in mind",
else , they get forgoten , and blank space appears in their place.

Au revoir!!!

Elias
Jan 8 '08 #5

Post your reply

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

Similar topics

2 posts views Thread by Frank Stajano | last post: by
3 posts views Thread by Terry Carroll | last post: by
1 post views Thread by Michael Yanowitz | last post: by
2 posts views Thread by sj | last post: by
reply views Thread by Andrew | last post: by
1 post views Thread by nish88 | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.