473,386 Members | 1,710 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,386 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 2440
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.