473,661 Members | 2,480 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 2465
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
5968
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 filling the remainder of the window. Mind you, this is a contrived test application to help me understand Tkinter and Python, not an actual application yet. I've trivially subclassed Tkinter.Canvas into ColorCanvas, added a bunch of ColorCanvases...
2
1908
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 2003, 12:03:29) on cygwin # First script, no bug # I want a canvas inside a frame inside a toplevel, with the canvas
1
6343
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 image in the central area of a simple menu-bar app as shown below in the first code sample. But, when I set up my app with a class, as shown below in the second code sample, the image disappears. How can I correct this? I'm sure the answer would...
3
8757
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 being processed. I can't get the image to update, though. I trimmed it down to a basic app indicating the problem and the code is at the end of this message. It should display the three listed sample images, one after another. The thing is,...
1
3595
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 I am hoping someone knows what I am doing wrong: 1) Pressing the Settings.. Button multiple times, brings up many instances of the Settings Panel. I just want it to bring up one. Is there an easy way to do that?
2
9448
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 my own code all I get is an empty widget. What is wrong with the following program? from Tkinter import *
0
2356
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 the modes for the different files but I am unsure If someone could examine my code and assist in helping me solve my problem(s)
1
11301
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 picture transparent. thank in advance import Tkinter from Tkconstants import * def window(tk):
0
1109
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 button for each 'tab' and uses .forget to hide the frames that aren't 'current'. I modified it to use a Scale slider bar instead of radio buttons. What my program does is create a parent notebook object, and in each notebook frame, child...
0
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8855
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8758
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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 we have to send another system
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.