From fbonniwell at ca.rr.com Fri Jun 1 18:48:16 2007 From: fbonniwell at ca.rr.com (fbonniwell) Date: Fri, 1 Jun 2007 09:48:16 -0700 (PDT) Subject: [Tkinter-discuss] Executing Tkinter UI from another class Message-ID: <10916531.post@talk.nabble.com> Hello, I'm still learning how to call class methods from other classes. I'm trying to figure out what is the best approach to executing a Tkinter UI from another class. It tells me that it expects two aurguments but received only 1. I expect it may have something to do with "app = App(root)" from class1.py. I also tried defining another procedure that would execute both but I'm still confused. Thanks for the help! Frank For example: Class1.py ----------------------------------------------- import Tkinter class App(Frame): def __init__(self , master): Frame.__init__(self, master) def makeFrames(self): code def makeRest(self): code def gerChars(self): code def createUI(self): #creates the UI self.makeFrames() self.makeRest() self.gerChars() root = Tk() app = App(root) app.pack() app.createUI() root.mainloop() ------------------------------------------------------- Class2.py calling class1.py to execute UI import class1 class ImportChar: def __init__(self): app = App(root) def AppendChar(self): code def RunItAll(self): self.ApppendChar() self.app.createUI() importchar = ImportChar() importchar.RunItAll() ------------------------------------------------- -- View this message in context: http://www.nabble.com/Executing-Tkinter-UI-from-another-class-tf3853383.html#a10916531 Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From sipickles at hotmail.com Wed Jun 6 18:18:31 2007 From: sipickles at hotmail.com (Simon Pickles) Date: Wed, 06 Jun 2007 17:18:31 +0100 Subject: [Tkinter-discuss] Newbie needs help with entrybox Message-ID: Hello, I am new to python and tkinter, but enjoying it so far. In trying to make a simple GUI I have stumbled on a problem binding an event to a function. I've got a listbox for output and an entrybox for input. How do I act on the text in the entry box when return is pressed? Here's my attempt: # GUI from Tkinter import* import tkMessageBox from time import ctime, time class CGUI: def __init__(self, master): frame = Frame(master, name="server") frame.pack() self.output = Listbox(frame, width=100, height=30) self.output.grid(row=0, column=0) self.inputBox = Entry(root, bd=5, width=100) self.inputBox.bind( "", self.__ParseInput(self.inputBox.get()) ) self.inputBox.pack(side=BOTTOM, expand=YES, fill=BOTH) def __ParseInput(self, s): self.output.insert(END, s) root = Tk() gui = CGUI(root) ------------------------------------------------------------------------- Your advice appreciated! Thanks Simon http://www.simonpickles.com --- http://www.squirtualreality.com _________________________________________________________________ The next generation of Hotmail is here! http://www.newhotmail.co.uk/ From tms43 at clearwire.net Wed Jun 6 18:36:32 2007 From: tms43 at clearwire.net (Teresa Stanton) Date: Wed, 6 Jun 2007 09:36:32 -0700 Subject: [Tkinter-discuss] Newbie needs help with entrybox In-Reply-To: References: Message-ID: <000901c7a858$d8d3dc20$8a7b9460$@net> I'm quite a noob to this also, but I can say that two things are missing: A function that your return event would call telling Python what to do when the event occurs, and mainloop. For instance, here is a sample code that when you click on it, will tell you where the mouse click event occurred: # File: bind1.py from Tkinter import * root = Tk() def callback(event): #this will be called later, the definition of the event. print "clicked at", event.x, event.y frame = Frame(root, width=100, height=100) frame.bind("", callback) #callback is the function, previously defined. frame.pack() root.mainloop() HTH Teresa -----Original Message----- From: tkinter-discuss-bounces at python.org [mailto:tkinter-discuss-bounces at python.org] On Behalf Of Simon Pickles Sent: Wednesday, June 06, 2007 9:19 AM To: tkinter-discuss at python.org Subject: [Tkinter-discuss] Newbie needs help with entrybox Hello, I am new to python and tkinter, but enjoying it so far. In trying to make a simple GUI I have stumbled on a problem binding an event to a function. I've got a listbox for output and an entrybox for input. How do I act on the text in the entry box when return is pressed? Here's my attempt: # GUI from Tkinter import* import tkMessageBox from time import ctime, time class CGUI: def __init__(self, master): frame = Frame(master, name="server") frame.pack() self.output = Listbox(frame, width=100, height=30) self.output.grid(row=0, column=0) self.inputBox = Entry(root, bd=5, width=100) self.inputBox.bind( "", self.__ParseInput(self.inputBox.get()) ) self.inputBox.pack(side=BOTTOM, expand=YES, fill=BOTH) def __ParseInput(self, s): self.output.insert(END, s) root = Tk() gui = CGUI(root) ------------------------------------------------------------------------- Your advice appreciated! Thanks Simon http://www.simonpickles.com --- http://www.squirtualreality.com _________________________________________________________________ The next generation of Hotmail is here! http://www.newhotmail.co.uk/ _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss From gigs at hi.t-com.hr Wed Jun 6 20:22:36 2007 From: gigs at hi.t-com.hr (Gigs_) Date: Wed, 06 Jun 2007 20:22:36 +0200 Subject: [Tkinter-discuss] Newbie needs help with entrybox In-Reply-To: References: Message-ID: <4666FB6C.7030606@hi.t-com.hr> Simon Pickles wrote: > Hello, I am new to python and tkinter, but enjoying it so far. > > In trying to make a simple GUI I have stumbled on a problem binding an event > to a function. I've got a listbox for output and an entrybox for input. How > do I act on the text in the entry box when return is pressed? > > Here's my attempt: > > # GUI > > from Tkinter import* > import tkMessageBox > from time import ctime, time > > class CGUI: > def __init__(self, master): > frame = Frame(master, name="server") > frame.pack() > self.output = Listbox(frame, width=100, height=30) > self.output.grid(row=0, column=0) > self.inputBox = Entry(root, bd=5, width=100) > self.inputBox.bind( "", > self.__ParseInput(self.inputBox.get()) ) > self.inputBox.pack(side=BOTTOM, expand=YES, fill=BOTH) > > def __ParseInput(self, s): > self.output.insert(END, s) > > > root = Tk() > > gui = CGUI(root) > > > ------------------------------------------------------------------------- > > > Your advice appreciated! > > Thanks > > Simon > http://www.simonpickles.com --- http://www.squirtualreality.com > > _________________________________________________________________ > The next generation of Hotmail is here! http://www.newhotmail.co.uk/ > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > __________ NOD32 2313 (20070606) Information __________ > > This message was checked by NOD32 antivirus system. > http://www.eset.com > > > > from Tkinter import * import tkMessageBox from time import ctime, time class CGUI(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.pack() self.output = Listbox(self, width=100, height=30) self.output.pack() self.inputBox = Entry(self, bd=5, width=100) self.inputBox.pack(side=BOTTOM, expand=YES, fill=BOTH) self.inputBox.bind("", lambda event: self.parseInput(self.inputBox.get())) def parseInput(self, s): self.output.insert(END, s) self.inputBox.delete(0, END) CGUI().mainloop() here it is dont use grid and pack in same parent. it will not work. i explain more but my english is bad and dont know how to express myself From jmcmonagle at velseis.com.au Thu Jun 7 00:58:46 2007 From: jmcmonagle at velseis.com.au (John McMonagle) Date: Thu, 07 Jun 2007 08:58:46 +1000 Subject: [Tkinter-discuss] Newbie needs help with entrybox In-Reply-To: <4666FB6C.7030606@hi.t-com.hr> References: <4666FB6C.7030606@hi.t-com.hr> Message-ID: <46673C26.7000706@velseis.com.au> Gigs_ wrote: > Simon Pickles wrote: >> Hello, I am new to python and tkinter, but enjoying it so far. >> >> In trying to make a simple GUI I have stumbled on a problem binding an event >> to a function. I've got a listbox for output and an entrybox for input. How >> do I act on the text in the entry box when return is pressed? >> >> Here's my attempt: >> >> # GUI >> >> from Tkinter import* >> import tkMessageBox >> from time import ctime, time >> >> class CGUI: >> def __init__(self, master): >> frame = Frame(master, name="server") >> frame.pack() >> self.output = Listbox(frame, width=100, height=30) >> self.output.grid(row=0, column=0) >> self.inputBox = Entry(root, bd=5, width=100) >> self.inputBox.bind( "", >> self.__ParseInput(self.inputBox.get()) ) >> self.inputBox.pack(side=BOTTOM, expand=YES, fill=BOTH) >> >> def __ParseInput(self, s): >> self.output.insert(END, s) >> >> >> root = Tk() >> >> gui = CGUI(root) >> >> >> ------------------------------------------------------------------------- >> >> You are not far away from success. Problem 1: you need to call mainloop after you instanciate the class. Problem 2: when you bind your __ParseInput function to the KeyPress-Return event, you are really binding the return result rather than the function name Problem 3: the event object gets passed to your function so you need to supply it as an argument Problem 4: passing self.inputBox.get() as an argument to the __ParseInput function will only pass the value of the Entry widget at the time the binding is made, not when you trigger the event. So you need to call it from within the function itself. See below for amendments to your code: from Tkinter import* import tkMessageBox from time import ctime, time class CGUI: def __init__(self, master): frame = Frame(master, name="server") frame.pack() self.output = Listbox(frame, width=100, height=30) self.output.grid(row=0, column=0) self.inputBox = Entry(root, bd=5, width=100) self.inputBox.bind( "", self.__ParseInput) self.inputBox.pack(side=BOTTOM, expand=YES, fill=BOTH) def __ParseInput(self, event): self.output.insert(END, self.inputBox.get()) root = Tk() if __name__ == '__main__': gui = CGUI(root) root.mainloop() > > > dont use grid and pack in same parent. it will not work. > Although gigs is right in saying that you cannot mix grid and pack in the same parent, in your case you have not. Your container hierarchy: root is the toplevel frame and inputBox are packed into root output is gridded into frame. So there is no contention here. Also, do not be tempted to adopt his style of inheriting Frame - your original approach is better. Frame is a container widget NOT a window. Regards, John From pollastri at iriti.cnr.it Fri Jun 8 11:59:54 2007 From: pollastri at iriti.cnr.it (Fabrizio Pollastri) Date: Fri, 08 Jun 2007 11:59:54 +0200 Subject: [Tkinter-discuss] visualtcl as ui designer for tkinter Message-ID: <4669289A.50004@iriti.cnr.it> Hello, I am trying to use VisualTcl as an interface designer. The tcl file produced by VisualTcl is executed in my application as root = Tk() root.tk.evalfile('my_tcl_gui.tcl') I have found two problems. First, the toplevel "root" supersede the toplevel options defined in the tcl file (typically the window title). Second, the tcl file evaluation stops for "argc" undefined. Similar tcl files created with TkproE do not suffer this problems. Thank for any help. Regards, F. Pollastri From january at uni-muenster.de Fri Jun 15 02:43:19 2007 From: january at uni-muenster.de (January Weiner) Date: Fri, 15 Jun 2007 02:43:19 +0200 Subject: [Tkinter-discuss] Ugly fonts with tkinter Message-ID: <454237550706141743s386e6c69x2a717290c8edd3c7@mail.gmail.com> I am sure this has been asked a hundred times, but I could not find an answer in Google. I have recently started programming using Tkinter and python. Before, I was heavily using Perl-Tk, so I have some experience with that kit. My system is Ubuntu 7.04. My problem are the extremly ugly bitmap fonts used by Tkinter. Here is an example: http://hell.pl/january/python_fonts_example.png I remember having a similar problem in perl-tk, and having for that two solutions: 1) choose a different font (optionAdd method of the main window with e.g. Arial 10) 2) recompiling perl-tk with an antialias option set, so that one gets fully anti-aliased fonts. First, I would like to use option (1), but I don't know enough of tkinter to find it. Furthermore, I would like to know what is the status on (2). Is tkinter using somehow its own tk libraries, or does it relies on system wide libraries? Do you have any experience with using antialiased fonts with tkinter? Cheers, j. -- ------------ January Weiner 3 ---------------------+--------------- Division of Bioinformatics, University of Muenster | Schlo?platz 4 (+49)(251)8321634 | D48149 M?nster http://www.uni-muenster.de/Evolution/ebb/ | Germany From fredrik at pythonware.com Fri Jun 15 08:31:49 2007 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 15 Jun 2007 08:31:49 +0200 Subject: [Tkinter-discuss] Ugly fonts with tkinter In-Reply-To: <454237550706141743s386e6c69x2a717290c8edd3c7@mail.gmail.com> References: <454237550706141743s386e6c69x2a717290c8edd3c7@mail.gmail.com> Message-ID: January Weiner wrote: > 1) choose a different font (optionAdd method of the main window with > e.g. Arial 10) > > First, I would like to use option (1), but I don't know enough of > tkinter to find it. use the option_add() method on the root widget. e.g. root.option_add("*Label*font", "Helvetica 15 bold") From woswwf at yahoo.co.uk Sun Jun 17 22:41:25 2007 From: woswwf at yahoo.co.uk (Brill IanT) Date: Sun, 17 Jun 2007 21:41:25 +0100 (BST) Subject: [Tkinter-discuss] single button threading Message-ID: <146481.5193.qm@web26604.mail.ukl.yahoo.com> I am writing an application which fetches and parses a large number of urls for hyperlinks. My problem is that when the prog is in the middle of the 'fetching' stage, the gui becomes almost completely unresponsive. This is not at all what I want. I want the user to be able to interact with the gui while this process is going on. Even if just one button, a 'stop' button, is the only thing working, I would be satisfied with that. Is there a way to perhaps thread a button or two while urllib2 is busy fetching a big list of urls? I ask this with some trepidation because I know how thread unfriendly tkinter is. If there is no solution to this, can anyone tell me if reconstructing the gui with wx would help with this matter? I don't want to do this because I am familiar with tk and find it far easier to work with, but I really have to find a way of solving this problem. Thank you very much for reading, and I hope someone can help me out. --------------------------------- Yahoo! Answers - Get better answers from someone who knows. Tryit now. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20070617/200aed12/attachment.htm From Cameron at phaseit.net Sun Jun 17 22:55:50 2007 From: Cameron at phaseit.net (Cameron Laird) Date: Sun, 17 Jun 2007 20:55:50 +0000 Subject: [Tkinter-discuss] single button threading In-Reply-To: <146481.5193.qm@web26604.mail.ukl.yahoo.com> References: <146481.5193.qm@web26604.mail.ukl.yahoo.com> Message-ID: <20070617205550.GA23108@lairds.us> On Sun, Jun 17, 2007 at 09:41:25PM +0100, Brill IanT wrote: . . . > I am writing an application which fetches and parses a large number of urls for hyperlinks. > > My problem is that when the prog is in the middle of the 'fetching' stage, the gui becomes almost completely unresponsive. > > This is not at all what I want. I want the user to be able to interact with the gui while this process is going on. Even if just one button, a 'stop' button, is the only thing working, I would be satisfied with that. > > Is there a way to perhaps thread a button or two while urllib2 is busy fetching a big list of urls? I ask this with some trepidation because I know how thread unfriendly tkinter is. > > If there is no solution to this, can anyone tell me if reconstructing the gui with wx would help with this matter? I don't want to do this because I am familiar with tk and find it far easier to work with, but I really have to find a way of solving this problem. > > Thank you very much for reading, and I hope someone can help me out. . . . There are several ways to achieve the responsiveness you describe within Tkinter. I'll be tied up the next couple of days; I hope an answer that delayed still helps you. From klappnase at web.de Mon Jun 18 10:50:13 2007 From: klappnase at web.de (Michael Lange) Date: Mon, 18 Jun 2007 10:50:13 +0200 Subject: [Tkinter-discuss] single button threading In-Reply-To: <146481.5193.qm@web26604.mail.ukl.yahoo.com> References: <146481.5193.qm@web26604.mail.ukl.yahoo.com> Message-ID: <20070618105013.729068d1.klappnase@web.de> On Sun, 17 Jun 2007 21:41:25 +0100 (BST) Brill IanT wrote: > I am writing an application which fetches and parses a large number of urls for hyperlinks. > > My problem is that when the prog is in the middle of the 'fetching' stage, the gui becomes almost completely unresponsive. > > This is not at all what I want. I want the user to be able to interact with the gui while this process is going on. Even if just one button, a 'stop' button, is the only thing working, I would be satisfied with that. > > Is there a way to perhaps thread a button or two while urllib2 is busy fetching a big list of urls? I ask this with some trepidation because I know how thread unfriendly tkinter is. > I did not find it that hard to use Tkinter with threads. You just have to make sure that all interaction with Tk is done from the main (gui) thread. Typically I use a bunch of variables to handle communication between Tkinter and the child thread, so the "Stop" button would set a "stop_child_thread" flag to True, whereas the child thread continually updates a "progress" flag that allows the gui to draw some visual feedback about the progress made by the child. I hope this helps Michael From Cameron at phaseit.net Tue Jun 19 21:27:51 2007 From: Cameron at phaseit.net (Cameron Laird) Date: Tue, 19 Jun 2007 19:27:51 +0000 Subject: [Tkinter-discuss] single button threading In-Reply-To: <20070618105013.729068d1.klappnase@web.de> References: <146481.5193.qm@web26604.mail.ukl.yahoo.com> <20070618105013.729068d1.klappnase@web.de> Message-ID: <20070619192751.GA4600@lairds.us> On Mon, Jun 18, 2007 at 10:50:13AM +0200, Michael Lange wrote: . . . > Brill IanT wrote: > > > I am writing an application which fetches and parses a large number of urls for hyperlinks. > > > > My problem is that when the prog is in the middle of the 'fetching' stage, the gui becomes almost completely unresponsive. > > > > This is not at all what I want. I want the user to be able to interact with the gui while this process is going on. Even if just one button, a 'stop' button, is the only thing working, I would be satisfied with that. > > > > Is there a way to perhaps thread a button or two while urllib2 is busy fetching a big list of urls? I ask this with some trepidation because I know how thread unfriendly tkinter is. > > > > I did not find it that hard to use Tkinter with threads. You just have to make sure that > all interaction with Tk is done from the main (gui) thread. Typically I use a bunch > of variables to handle communication between Tkinter and the child thread, so the > "Stop" button would set a "stop_child_thread" flag to True, whereas the child > thread continually updates a "progress" flag that allows the gui to draw some visual feedback > about the progress made by the child. > > I hope this helps . . . There certainly are people who regard Tkinter threading as touchy. I choose not to argue that point today. I *will* point out that, in essentially all common systems (not just Tkinter, and not just any particular operating system), you'll need to confine your GUI work to a single thread. Let's sidestep all that for right now, and look at an example of a responsive urllib2-using GUI in a single thread: from Tkinter import * from urllib2 import * master = Tk() def fetch_action(): l.configure(text = "Beginning download") l.after(0, download) def download(): global total_read global stop_reading URL = "http://wiki.python.org/moin/RecentChanges" f = urlopen(URL) total_read = 0 stop_reading = 0 l.after(0, read_more, f, 100) def read_more(handle, octets): global total_read global stop_reading if stop_reading: return print handle.read(octets), total_read += octets l.configure(text = "%d octets read" % total_read) l.after(1, read_more, handle, octets) def stop(): global stop_reading stop_reading = 1 l = Label(master, text = 40 * " ") b1 = Button(master, text = "Fetch", command = fetch_action) b2 = Button(master, text = "Stop reading", command = stop) l.pack() b1.pack() b2.pack() mainloop() I like to think this speaks for itself. If you execute this application for itself, you'll see a GUI that remains responsive even while urllib2 operations are proceeding. From pollastri at iriti.cnr.it Mon Jun 25 11:17:59 2007 From: pollastri at iriti.cnr.it (Fabrizio Pollastri) Date: Mon, 25 Jun 2007 11:17:59 +0200 Subject: [Tkinter-discuss] different results from the same tcl script Message-ID: <467F8847.5040709@iriti.cnr.it> Hello, in mixed python-tcl programming I found the following different behaviours of the same tcl script. If I type manually in the python interpreter the following lines >>> from Tkinter import * >>> w = Tk() >>> w.tk.evalfile('my_tcl_script.tcl') where my_tcl_script.tcl is #!/bin/sh package require Tk wm withdraw . toplevel .root wm title .root "My title" I obtain one toplevel window with title "My title", as expected. The same result is obtained with the tcl shell command % wish my_tcl_script.tcl Now, I wish to run the same instructions from a python script. So, I written the following script from time import * from Tkinter import * w = Tk() w.tk.evalfile('my_tcl_script.tcl') sleep(3) The result of this python script is nothing, no window appears. If anybody can explain the different behaviour and how to normalize it with the correct one, I will be very glad. Thank you in advance. F. Pollastri From pollastri at iriti.cnr.it Mon Jun 25 16:41:11 2007 From: pollastri at iriti.cnr.it (Fabrizio Pollastri) Date: Mon, 25 Jun 2007 16:41:11 +0200 Subject: [Tkinter-discuss] different results from the same tcl script Message-ID: <467FD407.9090803@iriti.cnr.it> Mohammad Tayseer wrote: > Finishing the program will close it, which will destroy the Tk object. > You have to call mainloop() at the end to stop the program from >closing The program waits for 3 seconds before finishing, so I must see the expected window for the same time, but this do not happen. F. Pollastri From m_tayseer82 at yahoo.com Mon Jun 25 19:20:44 2007 From: m_tayseer82 at yahoo.com (Mohammad Tayseer) Date: Mon, 25 Jun 2007 10:20:44 -0700 (PDT) Subject: [Tkinter-discuss] different results from the same tcl script In-Reply-To: <467FD407.9090803@iriti.cnr.it> Message-ID: <352029.24348.qm@web31111.mail.mud.yahoo.com> You have to call mainloop for any window to appear. I cannot remember the exact reason for this, but it was posted before on the mailing list Fabrizio Pollastri wrote: Mohammad Tayseer wrote: > Finishing the program will close it, which will destroy the Tk object. > You have to call mainloop() at the end to stop the program from >closing The program waits for 3 seconds before finishing, so I must see the expected window for the same time, but this do not happen. F. Pollastri _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss Mohammad Tayseer http://spellcoder.com/blogs/tayseer --------------------------------- Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20070625/b705100e/attachment.html From agent_barnes at yahoo.com Wed Jun 27 20:48:04 2007 From: agent_barnes at yahoo.com (Barnesdesdes) Date: Wed, 27 Jun 2007 11:48:04 -0700 (PDT) Subject: [Tkinter-discuss] Possibly n00bish question about ImageTk Message-ID: <11330353.post@talk.nabble.com> I've been trying to make a program which will import a png file and display it inside a frame. It actually works when I just run the code, but if I try to abstract the exact same code into a function, it fails. In the code below, if I just run it, it works. However, if I comment out the lines between "root=Tkinter.Tk()" and "moo(root)" and comment in "moo(root)", it no longer works. Instead of displaying the image, it just displays a gray frame of the correct size. Does anyone have any insights about what I'm doing wrong? import Image, ImageTk, Tkinter def moo(master): img = Image.open('plotfig.png') f = Tkinter.Frame(master, width=800, height=600) pi = ImageTk.PhotoImage(img) t = Tkinter.Label(f, image=pi) f.pack() t.place(x=0, y=0, width=800, height=600) t.pack() root = Tkinter.Tk() img = Image.open('plotfig.png') f = Tkinter.Frame(root, width=800, height=600) pi = ImageTk.PhotoImage(img) t = Tkinter.Label(f, image=pi) f.pack() t.place(x=0, y=0, width=800, height=600) t.pack() #moo(root) root.mainloop() Thanks very much. Alan -- View this message in context: http://www.nabble.com/Possibly-n00bish-question-about-ImageTk-tf3990201.html#a11330353 Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From mkieverpy at tlink.de Thu Jun 28 11:29:11 2007 From: mkieverpy at tlink.de (mkieverpy at tlink.de) Date: Thu, 28 Jun 2007 09:29:11 -0000 Subject: [Tkinter-discuss] Possibly n00bish question about ImageTk Message-ID: <20070628072843.AF085BB03@mail.terralink.de> Hi Alan, in your function 'moo' 'pi' is a local variable which gets garbage collected when the function returns. Thus your image goes to gc nirvana. Making 'pi' global like this def moo(master): global pi img = Image.open('plotfig.png') f = Tkinter.Frame(master, width=800, height=600) pi = ImageTk.PhotoImage(img) t = Tkinter.Label(f, image=pi) f.pack() t.place(x=0, y=0, width=800, height=600) t.pack() should do the trick. This is a guess as I am not using Image and ImageTk. But I had the same problem with Tix.PhotoImage. So I guess this is it. BTW you use 'place' and 'pack' for the label. As I understood your supposed to use exactly ONE geometry handler for a gui element in tk. Hope this helps, Matthias Kievernagel (mkiever/at/web/dot/de) From jmcmonagle at velseis.com.au Fri Jun 29 00:21:02 2007 From: jmcmonagle at velseis.com.au (John McMonagle) Date: Fri, 29 Jun 2007 08:21:02 +1000 Subject: [Tkinter-discuss] Possibly n00bish question about ImageTk In-Reply-To: <20070628072843.AF085BB03@mail.terralink.de> References: <20070628072843.AF085BB03@mail.terralink.de> Message-ID: <4684344E.4060901@velseis.com.au> mkieverpy at tlink.de wrote: > BTW you use 'place' and 'pack' for the label. As I understood > your supposed to use exactly ONE geometry handler for a gui element in tk. > This really only applies to widgets which are packed/placed/gridded into the same parent container. In his example he is packing a Frame into master then placing a Label into the Frame, so there is no contention.