473,287 Members | 3,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 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 2429
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

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

Similar topics

1
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
2
by: Frank Stajano | last post by:
The compact form of pack behaves differently (and I believe incorrectly) compared to the long form. The following two scripts demonstrate it, at least on this interpreter: Python 2.3.2 (#1, Oct 9...
1
by: midtoad | last post by:
I'm trying to display a GIF image in a label as the central area to a Tkinter GUI. The image does not appear, though a space is made for it. Why is this so? I notice that I can display a GIF...
3
by: Terry Carroll | last post by:
I've got a small batch image-processing program (it adds the time a digital photo was taken to the lower right of the image), and as a feature, I wanted to show a thumbnail of each image it was...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
2
by: sj | last post by:
I am just learning to use Tkinter and am having problems displaying image files. I am able to display an image using tutorials (such as http://www.daniweb.com/code/snippet296.html) But when I try...
0
by: Andrew | last post by:
Hello Ive been messing around with a simple raw image viewer using Pil and Tkinter However I am running into problems displaying the images they appear to be not correct I believe it is cause of...
1
by: nish88 | last post by:
hi to all... i'm working on an animation where i have to make the picture background.gif transparent. l'm not able to do it.can you please help me or tell me what codes i should add to make the...
0
by: execrable | last post by:
I am writing a simple (maybe a bit conveluded, but I just started learning Tkinter) program that uses a 'notebook' code snippet from a python cookbook. It creates a customizable frame and radio...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.