473,507 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why Image doesnt appear in a Tkinter child frame?

Elias Alhanatis
56 New Member
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 2451
bartonc
6,596 Recognized Expert Expert
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
Elias Alhanatis
56 New Member
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 Recognized Expert Expert
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
Elias Alhanatis
56 New Member
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
5959
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
1902
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
6294
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
8702
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
3585
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
9401
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
2350
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
11228
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
1106
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...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.