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

Strange problem with Tkinter... photos don't show on first iteration.

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 different pages. All that's
working fine...
The problem I'm having is that the images don't show onscreen the first
time the "first page" of results shows up. When I click the "search
again" button, and have more than the original results page to toggle
between, the images __do__ show up on the "first page" of results. (and
on the second, etc, etc.)
Which is to say, there's no error messages, and on the first "page",
the first time it's shown, the Toplevel formats correctly, and there
are spaces where the images should be that are the correct size,
just... no images.
It's baffling me. Perhaps someone can help.

Cheers, Al.

Script attached (apologies for it not being as neat as it probably
should be... :)
################################
from Tkinter import *
import sys
import cPickle

#opens gui and displays returned image thumbnails
class Im_Res1:
def __init__(self, master, lof, pageno):
self.master = root
root.withdraw()
nav_child(master, lof, pageno)
self.master.mainloop()

# the child window class
class nav_child:
def __init__(self, master, lof, pageno):
self.slave = Toplevel(master)
self.slave.grid()
self.slave.title("Image Results")
self.picts = []
lif = lof[pageno]
lenlif = len(lif)
for r in range(lenlif):
j = lif[r]
f = j[2]
self.img = PhotoImage(file = f)
self.picts.append(self.img)
print "self.picts = ", self.picts
for g in range(lenlif):
text = (lif[g])[1]# label text
def callback(text=text):

x=win32com.client.Dispatch('InternetExplorer.Appli cation.1')
x.Visible=1
x.Navigate(text)
p = open("VerRes.txt", 'w')
p.write(text)
p.close()
root.destroy()
if 0<= g < 6:
buttonx = Button(self.slave, text=(text), height=1,
width=23, command=callback)
buttonx.grid(row=3, column=g)
Label(self.slave, text=((lif[g])[0])).grid(row=2,
column=g)
self.Im = self.picts[g]
Label(self.slave, image=self.Im).grid(row=1, column=g)
elif 6<= g < 12:
buttonx = Button(self.slave, text=(text), height=1,
width=23, command=callback)
buttonx.grid(row=6, column=(g-6))
Label(self.slave, text=((lif[g])[0])).grid(row=5,
column=(g-6))
self.Im = self.picts[g]
Label(self.slave, image=self.Im).grid(row=4,
column=(g-6))
elif 12<= g < 18:
buttonx = Button(self.slave, text=(text), height=1,
width=23, command=callback)
buttonx.grid(row=9, column=(g-12))
Label(self.slave, text=((lif[g])[0])).grid(row=8,
column=(g-12))
self.Im = self.picts[g]
Label(self.slave, image=self.Im).grid(row=7,
column=(g-12))
elif 18<= g < 24:
buttonx = Button(self.slave, text=(text), height=1,
width=23, command=callback)
buttonx.grid(row=12, column=(g-18))
Label(self.slave, text=((lif[g])[0])).grid(row=11,
column=(g-18))
self.Im = self.picts[g]
Label(self.slave, image=self.Im).grid(row=10,
column=(g-18))
def search_again(lof=lof, pageno=pageno):
p = open("VerRes.txt", 'w')
pageno = pageno + 1
reslist = [pageno, 1, lof]
cPickle.dump(reslist, p)
p.close()
root.destroy()
SearchAgain = Button(self.slave, text='Search Again.',
fg="blue", command=search_again)
SearchAgain.grid(row=13, column=2, columnspan=2)
if pageno 0:
def Back_Cmd(lof=lof, pageno=pageno):
pageno = pageno - 1
nav_child(master, lof, pageno)
self.slave.destroy()
backbutton = Button(self.slave, text="Previous Page",
height=1, width=23, command=Back_Cmd)
backbutton.grid(row=13, column=0)
if pageno < (len(lof) - 1):
def Fwd_Cmd(lof=lof, pageno=pageno):
pageno = pageno + 1
nav_child(master, lof, pageno)
self.slave.destroy()
fwdbutton = Button(self.slave, text="Next Page", height=1,
width=23, command=Fwd_Cmd)
fwdbutton.grid(row=13, column=5)
def Quit_Search():
root.destroy()
sys.exit(0)
quitbutton = Button(self.slave, text='QUIT', fg="red",
command=Quit_Search)
quitbutton.grid(row=14, column=2, columnspan=2)

#############################################
"lof" is nested lists 'cos there's more than one page of more than one
image-
Images don't show on the first results page... *sigh*
Obviously, after the second iteration of the search, "lof" would look
more like:
[[["Some_Name", "http://some-url.net",
"C:\Image_File.GIF"]][["Other_Name", "http://Other-url.net",
"C:\Other_Image_File.GIF"]]]
##############################################
# run mainloop.

lof = [[["Some_Name", "http://some-url.net", "C:\Image_File.GIF"]]]

root = Tk()
app = Im_Res1(root, lof, 0)
root.mainloop()
################################################## ######

Aug 14 '06 #1
3 2338
al*********@gmail.com wrote:
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 different pages. All that's
working fine...
The problem I'm having is that the images don't show onscreen the first
time the "first page" of results shows up. When I click the "search
again" button, and have more than the original results page to toggle
between, the images __do__ show up on the "first page" of results. (and
on the second, etc, etc.)
Which is to say, there's no error messages, and on the first "page",
the first time it's shown, the Toplevel formats correctly, and there
are spaces where the images should be that are the correct size,
just... no images.
It's baffling me. Perhaps someone can help.
this is explained in the Python FAQ, and also in the note at the bottom
of this page:

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

</F>

Aug 14 '06 #2
Yup,
That's the problem. Can't thank you enough.
I'd read about Tkinter "garbage collection", but, like car crashes and
lung cancer, you never think it's going to happen to you...

thanks once again.
Cheers, Al.

Fredrik Lundh wrote:
al*********@gmail.com wrote:
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 different pages. All that's
working fine...
The problem I'm having is that the images don't show onscreen the first
time the "first page" of results shows up. When I click the "search
again" button, and have more than the original results page to toggle
between, the images __do__ show up on the "first page" of results. (and
on the second, etc, etc.)
Which is to say, there's no error messages, and on the first "page",
the first time it's shown, the Toplevel formats correctly, and there
are spaces where the images should be that are the correct size,
just... no images.
It's baffling me. Perhaps someone can help.

this is explained in the Python FAQ, and also in the note at the bottom
of this page:

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

</F>
Aug 14 '06 #3
And I say once again: I can't thank you enough.

YOU ROCK!

cheers, al.

(Just changed the code in my main program, and it WORKS! The previous
thankyou was only a preliminary.)
ps I really like python, too. :)

al*********@gmail.com wrote:
Yup,
That's the problem. Can't thank you enough.
I'd read about Tkinter "garbage collection", but, like car crashes and
lung cancer, you never think it's going to happen to you...

thanks once again.
Cheers, Al.

Fredrik Lundh wrote:
al*********@gmail.com wrote:
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 different pages. All that's
working fine...
The problem I'm having is that the images don't show onscreen the first
time the "first page" of results shows up. When I click the "search
again" button, and have more than the original results page to toggle
between, the images __do__ show up on the "first page" of results. (and
on the second, etc, etc.)
Which is to say, there's no error messages, and on the first "page",
the first time it's shown, the Toplevel formats correctly, and there
are spaces where the images should be that are the correct size,
just... no images.
It's baffling me. Perhaps someone can help.
this is explained in the Python FAQ, and also in the note at the bottom
of this page:

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

</F>
Aug 14 '06 #4

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

Similar topics

2
by: Stewart Midwinter | last post by:
I would like to link the contents of three OptionMenu lists. When I select an item from the first list (call it continents), the contents of the 2nd list (call it countries) would update. And in...
1
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
1
by: Russ Perry Jr | last post by:
I'm working on my first "real" C# project, and one of the first things I'm doing is putting some data up in a grid. I'm using a DataSet returned form running a stored proc as my grid.DataSource,...
5
by: cody | last post by:
I have a very funny/strange effect here. if I let the delegate do "return prop.GetGetMethod().Invoke(info.AudioHeader, null);" then I get wrong results, that is, a wrong method is called and I...
4
by: Chris | last post by:
Hi, I'm puzzled by some strange behavior when my Python/Tkinter application quits (on linux): the terminal from which I started Python is messed up. If start up python, then import the code...
3
by: Milagro | last post by:
Hello Everyone, I'm trying to debug someone elses php code. I'm actually a Perl programmer, with OO experience, but not in php. The code is supposed to upload a photo from a form and save it...
4
by: BartlebyScrivener | last post by:
Using Python on Debian Etch. What is the best way to paste a block of text in at the command prompt. I'm trying something like: Quote = raw_input("Paste quote here: ") Which works great...
1
by: alivip | last post by:
I integrat program to be GUI using Tkinter I try browser direction as you can see # a look at the Tkinter Text widget # use ctrl+c to copy, ctrl+x to cut selected text, # ctrl+v to...
1
by: jojo41300000 | last post by:
Hi, I am writing an application which will display the photos on the web pages. The photos are stored in the seperate machine but in the same LAN. First, when the user visit the web...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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.