473,387 Members | 1,542 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,387 software developers and data experts.

Tkinter, toplevel and images

Hi

I'm trying to build a small application that can display some images
in a toplevel window. I have this code:

def Results(master):
from Tkinter import Toplevel, Button, Label
from PIL import ImageTk

figures = ['first.png', 'second.png']

ResultsWindow = Toplevel(master)
ResultsWindow.title('Results')

picts = [ImageTk.PhotoImage(file = x) for x in figures]

butRW = Button(ResultsWindow, text = 'CLOSE', command =
ResultsWindow.destroy)
butRW.pack()

height = sum([x.height() for x in picts])
width = picts[0].width()

y = 0
for pict in picts:
label = Label(ResultsWindow,image=pict).pack()
y += pict.height()

from Tkinter import Tk
root = Tk()
Results(root)
root.mainloop()

and I just can see a grey window with a "close" button... However,
when I try the same code with the root I can see both images... Can
anyone give me a tip?

Thanks! :)
Aug 22 '08 #1
2 5498
On Aug 22, 9:17 am, Pedro <Pedro.Tarr...@gmail.comwrote:
Hi

I'm trying to build a small application that can display some images
in a toplevel window. I have this code:

def Results(master):
from Tkinter import Toplevel, Button, Label
from PIL import ImageTk

figures = ['first.png', 'second.png']

ResultsWindow = Toplevel(master)
ResultsWindow.title('Results')

picts = [ImageTk.PhotoImage(file = x) for x in figures]

butRW = Button(ResultsWindow, text = 'CLOSE', command =
ResultsWindow.destroy)
butRW.pack()

height = sum([x.height() for x in picts])
width = picts[0].width()

y = 0
for pict in picts:
label = Label(ResultsWindow,image=pict).pack()
y += pict.height()

from Tkinter import Tk
root = Tk()
Results(root)
root.mainloop()

and I just can see a grey window with a "close" button... However,
when I try the same code with the root I can see both images... Can
anyone give me a tip?

Thanks! :)
You can try making a class for the Tkinter.Toplevel window. I don't
have PIL, but I know if you query for a widget's value when the window
is not yet displayed, it will give a nearly 0-by-0 size result.

You can also try to set a size for the Toplevel window and see if the
images display.

I have not encountered this before, but I only know what I have read
from books (like Programming Python by O'Reilly) and have assumed.

Good luck.
Aug 22 '08 #2
Pedro wrote:
and I just can see a grey window with a "close" button... However,
when I try the same code with the root I can see both images... Can
anyone give me a tip?
this was cross-posted to the tkinter mailing list; in case someone
stumbles upon this via a search engine, here's a link that explains why
this happens:

http://effbot.org/tkinterbook/photoimage.htm#note

</F>

Aug 23 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fuzzyman | last post by:
I'm working on a presentation program that needs to produce 'full screen' images. The effect will be something like a powerpoint presentation. In actual fact it's a song database with lyrics -...
2
by: Michael Zhang | last post by:
My project uses Python-2.3.4 + Tkinter + PIL-1.1.4 to retrieve images from server and display those images. I created a thread (also a separate toplevel window) for displaying images and another...
6
by: max(01)* | last post by:
hi people. when i create a widget, such as a toplevel window, and then i destroy it, how can i test that it has been destroyed? the problem is that even after it has been destroyed, the instance...
0
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo...
1
by: yvesd | last post by:
hello i want to intercept tkinter python system events like wm_delete_window and if possible for any window, but the newest code I've produced give me an error : Traceback (most recent call...
3
by: aldonnelley | last post by:
Hi all. Just having a weird problem with tkinter. I'm trying to make a gui that shows results from an image search, with a "forward" and "back" button so the user can compare results from...
4
by: Gigs_ | last post by:
class MenuDemo(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) self.pack(expand=YES, fill=BOTH) self.createWidgets() def createWidgets(self): self.makeMenuBar()...
7
by: Chris | last post by:
Hi, If a user resizes a Toplevel window, or I set a Toplevel's geometry using the geometry() method*, is there any way to have the geometry reset to that required for all the widgets? I think...
3
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.