Hello everybody!!
I would like some help with the following problem:
I have the following piece of code: -
-
from Tkinter import *
-
root = Tk()
-
menuframe=Frame(root,height="1c",width="30c",bg="#d5ab6c",bd=2,relief=RAISED)
-
menuframe.pack(expand=NO,side=TOP,fill=BOTH)
-
mainframe=Frame(root,height="19.8c",width="30c",bg="#d5ab3c",bd=2,relief=RAISED)
-
mainframe.pack()#expand=NO,side=TOP,fill=BOTH)
-
CN=Canvas(mainframe,height="19.8c",width="30c",bg="#d5ab3c")
-
images="C:/Python25/pic.GIF"
-
photo1=PhotoImage(file=images)
-
CN.create_image("15c","9.9c",image=photo1)
-
CN.pack()
-
-
mBar = Frame(menuframe, relief=RAISED, borderwidth=2)
-
mBar.pack(fill=X,side=LEFT)
-
-
ArxBtn = makeArxiaMenu()
-
KinBtn = makeKiniseisMenu()
-
EktBtn = makeEktyposeisMenu()
-
VoiBtn = makeVoithitikaMenu()
-
RytBtn = makeRythmiseisMenu()
-
EpiBtn = makeEpikoinoniesMenu()
-
mBar.tk_menuBar(ArxBtn,KinBtn,EktBtn,VoiBtn,RytBtn,EpiBtn)
-
-
-
root.title('Window App by Elias')
-
root.geometry("1142x800")
-
root.mainloop()
-
-
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: -
-
def Polites():
-
global mainframe
-
mainframe.destroy()
-
mainframe=Frame(root,height="19.8c",width="30c",bd=4,relief=RAISED)
-
mainframe.pack(anchor=SW)
-
-
Pict=Canvas(mainframe,height="19.8c",width="30c",bg="#d5ab3c")
-
images="C:/Python25/maria.GIF"
-
photo1=PhotoImage(file=images)
-
Pict.create_image("15c","9.9c",image=photo1)
-
Pict.grid()
-
-
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
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
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.... -
-
from Tkinter import *
-
-
-
def f1():
-
mainframe=Frame(root)
-
mainframe.pack()
-
CN=Canvas(mainframe,height="9.8c",width="15c",bg="#d5ab3c")
-
images="C:/Python25/Bother/3.GIF"
-
photo1=PhotoImage(file=images)
-
CN.create_image("7.55c","4.9c",image=photo1)
-
CN.pack()
-
-
-
def f2():
-
mainframe2=Frame(root)
-
mainframe2.pack()
-
CN=Canvas(mainframe2,height="9.8c",width="15c",bg="#d5ab3c")
-
images="C:/Python25/GIFS/5bl.103b.GIF"
-
photo1=PhotoImage(file=images)
-
CN.create_image("7.5c","4.9c",image=photo1)
-
CN.pack()
-
-
root=Tk()
-
f1()
-
f2()
-
root.mainloop()
-
-
It seems like i am missing something basic here.....
Thanks again for your time... :)
Elias
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: -
-
def Polites():
-
global mainframe
-
mainframe.destroy()
-
mainframe=Frame(root,height="19.8c",width="30c",bd=4,relief=RAISED)
-
mainframe.pack(anchor=SW)
-
-
Pict=Canvas(mainframe,height="19.8c",width="30c",bg="#d5ab3c")
-
images="C:/Python25/maria.GIF"
-
photo1=PhotoImage(file=images)
-
Pict.create_image("15c","9.9c",image=photo1)
-
Pict.grid()
-
-
(as you said) works because it uses widget.grid() instead of .pack().
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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...
|
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,...
|
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?
| |
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 *
|
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)
|
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):
|
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...
|
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...
|
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...
| |
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...
|
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,...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |