From mfranklin1 at gatwick.westerngeco.slb.com Wed Jun 1 13:42:23 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed, 01 Jun 2005 12:42:23 +0100 Subject: [Tkinter-discuss] tk 8.3 and unicode In-Reply-To: <20050527140617.GA8187@unpythonic.net> References: <20050527140617.GA8187@unpythonic.net> Message-ID: Jeff Epler wrote: > This bug must have been fixed between Python 2.2 + Tk 8.3 and Python 2.3 > + Tk 8.4. > > Running a slightly different test program, I get this output on Fedora > Core 1 (Python 2.2 + Tk 8.3): > '\xc2\xa3' > and this output on Fedora Core 2 (Python 2.3 + Tk 8.4): > u'\xa3' > > You could try defining a > class UStringVar(Tkinter.StringVar): > def get(self): > return Tkinter.StringVar.get(self).decode("utf-8") > and using that instead. This seemed to work on the FC1 system, at least > when LANG=en_US.UTF-8 -- this might depend on tcl's idea of the sytem > encoding, though. > Thanks Jeff, The call to decode() when I get the entry's textvariable does indeed fix the problem. I now have a similar (but wholly different;-) problem related to a filename containing a Unicode character, however, I think I'll resolve this but not allowing my users to do this (I believe it is dependent on more than just Python / Tk - It must involve the OS at some level) Cheers, Martin. From glee at pharsight.com Tue Jun 7 04:30:11 2005 From: glee at pharsight.com (Greg Lee) Date: Mon, 6 Jun 2005 19:30:11 -0700 Subject: [Tkinter-discuss] tkinter and threading Message-ID: <08AAC77C2656414E91980F8EBB1E7F01037EFC0F@electra.corp.pharsight.com> Are Tkinter callbacks run in separate threads? Do I need to use threading locks to protect data shared between callbacks that can run at the same time? I'm running Python 2.3 and Tkinter on Windows. I have two callbacks: cb_close and cb_run. cb_close cleans up, then uses Tkinter.Toplevel.destroy; it is bound to WM_DELETE_WINDOW via Tkinter.Toplevel.protocol. cb_run uses a COM component to perform a lengthy operation. The COM component calls back to the Python world often enough that I can keep my GUI responsive using Tkinter.Toplevel.update. Bad things happen if I allow cb_close to call destroy while cb_run is in progress: cb_run eventually asks the Tkinter world to post a completion dialog. To keep this from happening I use a state variable to tell cb_close that it should not call destroy if cb_run is in progress and to tell cb_run that it should not execute if a cb_close is in progress. I can definitely get cb_close to run at the same time as cb_run, which suggests that the Tkinter eventloop executes its callbacks in separate threads. All this lead me to use a lock to protect read/write of the state variable. Was this necessary? Is there something in the way that Tkinter handles callbacks that automatically protects shared data structures? -------------------------------------------- Greg Lee / Pharsight Corporation / Suite 200 800 W El Camino / Mountain View CA 94040 voice: 650-314-3860 / fax: 650-314-3810 This email message (including any attachments) is for the sole use of the intended recipient and may contain confidential and proprietary information. Any disclosure or distribution to third parties that is not specifically authorized by the sender is prohibited. If you are not the intended recipient, please contact the sender (greg at pharsight.com) by reply email and destroy all copies of the original message. Thank you. From Mark.English at liffe.com Tue Jun 7 10:58:35 2005 From: Mark.English at liffe.com (Mark English) Date: Tue, 7 Jun 2005 09:58:35 +0100 Subject: [Tkinter-discuss] gui/thread issues Message-ID: <40E605146701DE428FAF21286A97D3090457E855@wphexa02.corp.lh.int> > Date: Mon, 23 May 2005 14:25:04 -0400 > From: Perry Greenfield > I think the problem is that, by and large, almost all uses of GUIs > are centered on their being standalone applications and thus > little thought is given to having a command line coexisting > with the GUI. > Our needs are pretty atypical in this regard. Count me in as another atypical user. I've had additional problems running through a plain Python interpreter if I don't use the main process thread as the main GUI thread on Windows XP. Typically the program will simply crash at some point. I'd like to be able to just import a module and call a function to run its GUI and still be able to continue at the command prompt. I suspect if I understood Tkinter better I could make this problem go away, which makes it all the more frustrating. When I have the time I'll try to create a simple test case and post it. Regards, Mark ----------------------------------------------------------------------- The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this email may be unlawful. If you have received this email in error, please notify the sender immediately and delete it from your system. The views expressed in this message do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary companies. ----------------------------------------------------------------------- From jepler at unpythonic.net Tue Jun 7 15:57:41 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 7 Jun 2005 08:57:41 -0500 Subject: [Tkinter-discuss] tkinter and threading In-Reply-To: <08AAC77C2656414E91980F8EBB1E7F01037EFC0F@electra.corp.pharsight.com> References: <08AAC77C2656414E91980F8EBB1E7F01037EFC0F@electra.corp.pharsight.com> Message-ID: <20050607135737.GE3821@unpythonic.net> No, Tkinter callbacks are not run in separate threads. When you see cb_close being called during cb_run, it's all in a single thread, with a call stack that looks like cb_close update cb_run mainloop i.e., when cb_run calls update, events (including "the user clicked a button", "pressed a key", etc.) are handled, leading to this effect. You may be able to use update_idletasks instead of update. They have different semantics as to which events they handle. update_idletasks should let things like resizing and repainting windows work, while delaying the response to user actions like clicking until an update or a return to the mainloop. I've included a copy of the update manpage below. Tcl's "update" command is the .update() method, and "update idletasks" is the .update_idletasks() method. Jeff update(n) Tcl Built-In Commands update(n) ______________________________________________________________________________ NAME update - Process pending events and idle callbacks SYNOPSIS update ?idletasks? _________________________________________________________________ DESCRIPTION This command is used to bring the application ``up to date'' by enter- ing the event loop repeatedly until all pending events (including idle callbacks) have been processed. If the idletasks keyword is specified as an argument to the command, then no new events or errors are processed; only idle callbacks are invoked. This causes operations that are normally deferred, such as display updates and window layout calculations, to be performed immedi- ately. The update idletasks command is useful in scripts where changes have been made to the application's state and you want those changes to appear on the display immediately, rather than waiting for the script to complete. Most display updates are performed as idle callbacks, so update idletasks will cause them to run. However, there are some kinds of updates that only happen in response to events, such as those trig- gered by window size changes; these updates will not occur in update idletasks. The update command with no options is useful in scripts where you are performing a long-running computation but you still want the applica- tion to respond to events such as user interactions; if you occasion- ally call update then user input will be processed during the next call to update. SEE ALSO after(n), bgerror(n) KEYWORDS event, flush, handler, idle, update Tcl 7.5 update(n) On Mon, Jun 06, 2005 at 07:30:11PM -0700, Greg Lee wrote: > Are Tkinter callbacks run in separate threads? Do I need to use threading locks to protect data shared between callbacks that can run at the same time? I'm running Python 2.3 and Tkinter on Windows. > > I have two callbacks: cb_close and cb_run. cb_close cleans up, then uses Tkinter.Toplevel.destroy; it is bound to WM_DELETE_WINDOW via Tkinter.Toplevel.protocol. > > cb_run uses a COM component to perform a lengthy operation. The COM component calls back to the Python world often enough that I can keep my GUI responsive using Tkinter.Toplevel.update. > > Bad things happen if I allow cb_close to call destroy while cb_run is in progress: cb_run eventually asks the Tkinter world to post a completion dialog. To keep this from happening I use a state variable to tell cb_close that it should not call destroy if cb_run is in progress and to tell cb_run that it should not execute if a cb_close is in progress. > > I can definitely get cb_close to run at the same time as cb_run, which suggests that the Tkinter eventloop executes its callbacks in separate threads. All this lead me to use a lock to protect read/write of the state variable. Was this necessary? Is there something in the way that Tkinter handles callbacks that automatically protects shared data structures? > > -------------------------------------------- > Greg Lee / Pharsight Corporation / Suite 200 > 800 W El Camino / Mountain View CA 94040 > voice: 650-314-3860 / fax: 650-314-3810 > > This email message (including any attachments) > is for the sole use of the intended recipient > and may contain confidential and proprietary > information. Any disclosure or distribution > to third parties that is not specifically > authorized by the sender is prohibited. > If you are not the intended recipient, please > contact the sender (greg at pharsight.com) by reply > email and destroy all copies of the original > message. Thank you. > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050607/fb382ef5/attachment.pgp From william.ohiggins at utoronto.ca Wed Jun 15 18:23:51 2005 From: william.ohiggins at utoronto.ca (William O'Higgins) Date: Wed, 15 Jun 2005 12:23:51 -0400 Subject: [Tkinter-discuss] First Tkinter program Message-ID: <20050615162351.GA3052@sillyrabbi.dyndns.org> I am just starting out with Python, in hopes of getting my head around OO programming. I am running into trouble figuring out how to structure a GUI front-end for a simple program. Here's the general visual structure: Listbox populated by a list Some number of textentry and textarea pairs (five? or from a list?) Button one - says "Next" and it stores the contents of the textentry and textarea pairs (in a dictionary tied to the list entry seems natural), and then clears the interface to allow more entries Button two - "Done" - stores the contents of the textentry and textarea pairs and then closes the window. That's really it - very simple, but too much for me - I haven't even written a list box test that actually works - I do not understand OO well enough to make sense of examples (I don't really get what a constructor does, or understand the interactions of classes and instances of TKinter objects). The underlying functionality is easy - I can write it to use the command line or text files no problem - but the interface i giving me fits. Any pointers would be welcome. Thanks. -- yours, William -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050615/77600d82/attachment.pgp From stewart.midwinter at gmail.com Wed Jun 15 21:36:01 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Wed, 15 Jun 2005 13:36:01 -0600 Subject: [Tkinter-discuss] Fwd: First Tkinter program In-Reply-To: References: <20050615162351.GA3052@sillyrabbi.dyndns.org> Message-ID: William, you sound like a candidate for one of the many introductions to Tkinter that are available. You found this list, so that's a start. Now you could try visiting the Tkinter wiki and take a look at some of the resources available there. It's at http://tkinter.unpy.net/wiki/ Unless what you are asking is for someone to write some widgets for you, there is no alternative to investing some time to learn the basics of Tkinter. Otherwise you will flail around endlessly and in the end spend more time than if you had devoted a minimal amount of time to educating yourself. cheers S -- Stewart Midwinter stewart at midwinter.ca stewart.midwinter at gmail.com Skype: midtoad From william.ohiggins at utoronto.ca Thu Jun 16 15:45:29 2005 From: william.ohiggins at utoronto.ca (William O'Higgins) Date: Thu, 16 Jun 2005 09:45:29 -0400 Subject: [Tkinter-discuss] First Tkinter program In-Reply-To: References: <20050615162351.GA3052@sillyrabbi.dyndns.org> Message-ID: <20050616134529.GA7948@sillyrabbi.dyndns.org> On Wed, Jun 15, 2005 at 01:35:38PM -0600, Stewart Midwinter wrote: >William, you sound like a candidate for one of the many introductions >to Tkinter that are available. You found this list, so that's a >start. Now you could try visiting the Tkinter wiki and take a look >at some of the resources available there. It's at >http://tkinter.unpy.net/wiki/ I have been to the wiki, but like all wikis, it is incomplete, the widgets I need more explanation of are not covered (listbox for example) and the recipes are overspecialized. The links to other resources are the same as those on python.org, which I have exhausted before contacting this list. >Unless what you are asking is for someone to write some widgets for >you, No, what I need is some explanatory help on what the structures inherent in Tkinter code *mean*. >there is no alternative to investing some time to learn the >basics of Tkinter. Otherwise you will flail around endlessly and in >the end spend more time than if you had devoted a minimal amount of >time to educating yourself. Thank you for flip assessment of the time I've spent, but you have no idea what I've done before contacting the list (which is partly my fault for not explaining my work to date). I would think that on a list with as little volume as this one you might be more polite. Now, perhaps someone else could contribute - here's what I need: Is there a reason that all the example programs I've seen start by defining a class for the actions, which has an __init__ function that refers to "self" all over the place, then creates an instance of a Tk() object, and then calls the class for the actions on (with?) the new Tk()instance? None of the examples seem to code in a straight line, and I'm having trouble following the progression of the "simple" examples. Can Tkinter programs been developed in a flat structure, without the class within class stuff that's hindering my understanding? Thanks. -- yours, William -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050616/8411258c/attachment.pgp From jepler at unpythonic.net Thu Jun 16 19:12:08 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 16 Jun 2005 12:12:08 -0500 Subject: [Tkinter-discuss] First Tkinter program In-Reply-To: <20050616134529.GA7948@sillyrabbi.dyndns.org> References: <20050615162351.GA3052@sillyrabbi.dyndns.org> <20050616134529.GA7948@sillyrabbi.dyndns.org> Message-ID: <20050616171208.GB1763@unpythonic.net> On Thu, Jun 16, 2005 at 09:45:29AM -0400, William O'Higgins wrote: > None of the examples seem to code in a straight line, and I'm having > trouble following the progression of the "simple" examples. Can Tkinter > programs been developed in a flat structure, without the class within > class stuff that's hindering my understanding? Thanks. Sure they can. I didn't read your original post, but here's a straight-line Tkinter program that creates a listbox with a scrollbar. When the selected item changes, the 'changed' function is executed, and prints (to the console) some information about the selection. Of course, this example *does* use classes, since Tkinter.Tk, Tkinter.Scrollbar, and friends are all classes. Jeff from Tkinter import * t = Tk() s = Scrollbar(t) l = Listbox(t, yscrollcommand=s.set) s.configure(command=l.yview) l.pack(side=LEFT, fill=BOTH, expand=YES) s.pack(side=LEFT, fill=Y) for i in range(1, 101): l.insert(END, "Item %d" % i) def changed(event): index = event.widget.curselection() if isinstance(index, (list, tuple)): index = index[0] print "Item index:", index print "Item value:", event.widget.get(index) l.bind("<>", changed) t.mainloop() -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050616/f0239f92/attachment.pgp From harlinseritt at yahoo.com Fri Jun 17 21:09:58 2005 From: harlinseritt at yahoo.com (Harlin Seritt) Date: Fri, 17 Jun 2005 12:09:58 -0700 (PDT) Subject: [Tkinter-discuss] Zen of Learning Tkinter or any other type of technology out there for that matter In-Reply-To: Message-ID: <20050617190958.55755.qmail@web52209.mail.yahoo.com> Hi William, True, you can get some rather curt answers on some of these lists -- try not to take these sort of things too personally but rather take what you need from it and discard the rest. If you fight back, no doubt you'll get a flame going or --most likely-- you'll get ignored and almost certainly no one will help you again. So, in short, you can't control what others do -- in life or online. Now onto Tkinter... My advice to you as far as really getting into Tkinter and understanding how it all works is for you to take a look at Frederik Lundh's fine tutorial and reference here: http://www.pythonware.com/library/tkinter/introduction/. This was more than adequate to get me up and running about 2 years ago. Once you get an idea of the basic framework of how Tkinter works, you may begin to think like I do: How come other GUI toolkits (simple ones like Java Swing, .NET et al) are not organized and thought out in the same fashion? I'll give you an example of what I mean. Tkinter GUI construction is based on a few components that you'll see over and over: Widget classes themselves: Ex: Button, Label, Entry Widget options: Ex: bordersize, relief, text, etc. Widget methods: Ex: config(), after(), etc. Also there are other components to consider: Placing widgets: You'll find these three methods are all you'll need for layout... pack(): the most difficult perhaps but gives you the most flexibility ... certainly easier than using most of Java Swing layouts ;-) grid(): allows one to place widgets in a grid place(): if you insist on having total control of placement then use this. Note that it won't look near as good as pack() if your user tries to expand your app. Custom events (bind()): Most of the Tkinter widgets will have their own default events but by designing your own you'll find that you can have an almost infinite arrangement of events. Window protocols: These allow you to manipulate the windows almost like MFC or X/Motif (well, at least to me!) Tkinter constants: As 'constant' implies, there are many pre-designed constants that allow one to use very plain language to describe a widget's option or set variables that correspond to widget values. And there are quite a few others, but I'll let you discover them on your own ;-). You'll find that you don't have to have a lot of underlying GUI framework knowledge (for your particular platform) to pull off a great-looking GUI app in just a few minutes! After you're done with Mr. Lundh's fine tutorial, I suggest you go buy John Grayson's Python_and_Tkinter_Programming book from Manning publications (you can get it here: http://www.manning.com/books/grayson). It is almost 700 pages of pure Tkinter code. If I'm not mistaken, these days you can actually buy it in PDF format! Some of it is intermediate and advanced, so I advise you to look hard at the aforementioned tutorial and post your questions as well on comp.lang.python newsgroup before really diving in. You'll find that you'll get help from a lot of different Tkinter pros there -- even from the effbot himself (Frederik). An extra note... in the John Grayson book in the preface, John mentions that he is an avid martial arts disciple. In it one of his teachers mentions to him and other students that there are a few concepts that might not be taught directly. The master tells them a lot of times you'll have to STEAL these concepts from me. And so, you must do that occasionally. Google is your friend, as the saying goes. Google as much as possible. Read books. Ask many many questions in the right places while ignoring flames when appropriate but always learn from what tidbits you'll be given from these people. Technologists are only too happy to show how much they know even if they intend to mildly insult you. Steal their knowledge whenever possible. Sorry for all the zen but hopefully this helps you. Good luck, Harlin Seritt tkinter-discuss-request at python.org wrote: Send Tkinter-discuss mailing list submissions to tkinter-discuss at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tkinter-discuss or, via email, send a message with subject or body 'help' to tkinter-discuss-request at python.org You can reach the person managing the list at tkinter-discuss-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Tkinter-discuss digest..." Today's Topics: 1. Re: First Tkinter program (William O'Higgins) 2. Re: First Tkinter program (Jeff Epler) ---------------------------------------------------------------------- Message: 1 Date: Thu, 16 Jun 2005 09:45:29 -0400 From: William O'Higgins Subject: Re: [Tkinter-discuss] First Tkinter program To: tk Message-ID: <20050616134529.GA7948 at sillyrabbi.dyndns.org> Content-Type: text/plain; charset="us-ascii" On Wed, Jun 15, 2005 at 01:35:38PM -0600, Stewart Midwinter wrote: >William, you sound like a candidate for one of the many introductions >to Tkinter that are available. You found this list, so that's a >start. Now you could try visiting the Tkinter wiki and take a look >at some of the resources available there. It's at >http://tkinter.unpy.net/wiki/ I have been to the wiki, but like all wikis, it is incomplete, the widgets I need more explanation of are not covered (listbox for example) and the recipes are overspecialized. The links to other resources are the same as those on python.org, which I have exhausted before contacting this list. >Unless what you are asking is for someone to write some widgets for >you, No, what I need is some explanatory help on what the structures inherent in Tkinter code *mean*. >there is no alternative to investing some time to learn the >basics of Tkinter. Otherwise you will flail around endlessly and in >the end spend more time than if you had devoted a minimal amount of >time to educating yourself. Thank you for flip assessment of the time I've spent, but you have no idea what I've done before contacting the list (which is partly my fault for not explaining my work to date). I would think that on a list with as little volume as this one you might be more polite. Now, perhaps someone else could contribute - here's what I need: Is there a reason that all the example programs I've seen start by defining a class for the actions, which has an __init__ function that refers to "self" all over the place, then creates an instance of a Tk() object, and then calls the class for the actions on (with?) the new Tk()instance? None of the examples seem to code in a straight line, and I'm having trouble following the progression of the "simple" examples. Can Tkinter programs been developed in a flat structure, without the class within class stuff that's hindering my understanding? Thanks. -- yours, William -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050616/8411258c/attachment-0001.pgp ------------------------------ Message: 2 Date: Thu, 16 Jun 2005 12:12:08 -0500 From: Jeff Epler Subject: Re: [Tkinter-discuss] First Tkinter program To: "William O'Higgins" Cc: tk Message-ID: <20050616171208.GB1763 at unpythonic.net> Content-Type: text/plain; charset="us-ascii" On Thu, Jun 16, 2005 at 09:45:29AM -0400, William O'Higgins wrote: > None of the examples seem to code in a straight line, and I'm having > trouble following the progression of the "simple" examples. Can Tkinter > programs been developed in a flat structure, without the class within > class stuff that's hindering my understanding? Thanks. Sure they can. I didn't read your original post, but here's a straight-line Tkinter program that creates a listbox with a scrollbar. When the selected item changes, the 'changed' function is executed, and prints (to the console) some information about the selection. Of course, this example *does* use classes, since Tkinter.Tk, Tkinter.Scrollbar, and friends are all classes. Jeff from Tkinter import * t = Tk() s = Scrollbar(t) l = Listbox(t, yscrollcommand=s.set) s.configure(command=l.yview) l.pack(side=LEFT, fill=BOTH, expand=YES) s.pack(side=LEFT, fill=Y) for i in range(1, 101): l.insert(END, "Item %d" % i) def changed(event): index = event.widget.curselection() if isinstance(index, (list, tuple)): index = index[0] print "Item index:", index print "Item value:", event.widget.get(index) l.bind("< >", changed) t.mainloop() -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050616/f0239f92/attachment-0001.pgp ------------------------------ _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss End of Tkinter-discuss Digest, Vol 16, Issue 5 ********************************************** __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050617/e483f3fc/attachment.htm From klappnase at web.de Tue Jun 21 20:01:56 2005 From: klappnase at web.de (Michael Lange) Date: Tue, 21 Jun 2005 20:01:56 +0200 Subject: [Tkinter-discuss] Help: _tkinter.createfilehandler not supported for threaded Tcl Message-ID: <20050621200156.3df2c014.klappnase@web.de> Hello list, the following error happened on a program I wrote that uses tkinter.createfilehandler() to catch the output of a shell command on someone else's box (for me it runs fine): Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1345, in __call__ return self.func(*args) File "/usr/local/bin/pyfloppy", line 293, in start self.format() File "/usr/local/bin/pyfloppy", line 303, in format self.mkfilehandler(self.pp, self.get_msg) File "/usr/local/bin/pyfloppy", line 379, in mkfilehandler tkinter.createfilehandler(fileobject, READABLE, function) RuntimeError: _tkinter.createfilehandler not supported for threaded Tcl When I googled for the traceback one of the results said: > If your Tcl installation is threaded, you should use > tkapp.createfilehandler instead. however (on my box) I cannot find tkapp anywhere (or should it be _tkinter.tkapp ?). Any help would be greatly appreciated. Thanks in advance Michael From jepler at unpythonic.net Tue Jun 21 20:24:19 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 21 Jun 2005 13:24:19 -0500 Subject: [Tkinter-discuss] Help: _tkinter.createfilehandler not supported for threaded Tcl In-Reply-To: <20050621200156.3df2c014.klappnase@web.de> References: <20050621200156.3df2c014.klappnase@web.de> Message-ID: <20050621182419.GB13744@unpythonic.net> On Tue, Jun 21, 2005 at 08:01:56PM +0200, Michael Lange wrote: > When I googled for the traceback one of the results said: > > > If your Tcl installation is threaded, you should use > > tkapp.createfilehandler instead. > > however (on my box) I cannot find tkapp anywhere (or should it be _tkinter.tkapp ?). I think this means the .tk attribute of any widget object, or the object returned by _tkinter.create() if you aren't using Tkinter widget classes. >>> import Tkinter >>> t = Tkinter.Tk() >>> t.tk Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050621/e3f08b93/attachment.pgp From klappnase at web.de Wed Jun 22 11:24:48 2005 From: klappnase at web.de (Michael Lange) Date: Wed, 22 Jun 2005 11:24:48 +0200 Subject: [Tkinter-discuss] Help: _tkinter.createfilehandler not supported for threaded Tcl In-Reply-To: <20050621182419.GB13744@unpythonic.net> References: <20050621200156.3df2c014.klappnase@web.de> <20050621182419.GB13744@unpythonic.net> Message-ID: <20050622112448.03594652.klappnase@web.de> On Tue, 21 Jun 2005 13:24:19 -0500 Jeff Epler wrote: > > I think this means the .tk attribute of any widget object, or the object > returned by _tkinter.create() if you aren't using Tkinter widget > classes. > > >>> import Tkinter > >>> t = Tkinter.Tk() > >>> t.tk > > > Jeff > Thanks Jeff, of course you are right, the tk attribute has a createfilehandler() method. Now if I replace tkinter.createfilehandler() with self.tk.createfilehandler() it seems to work the same way for me. Can anyone verify if this will do the trick with threaded tcl ? Best regards Michael From jepler at unpythonic.net Wed Jun 22 14:54:08 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 22 Jun 2005 07:54:08 -0500 Subject: [Tkinter-discuss] Help: _tkinter.createfilehandler not supported for threaded Tcl In-Reply-To: <20050622112448.03594652.klappnase@web.de> References: <20050621200156.3df2c014.klappnase@web.de> <20050621182419.GB13744@unpythonic.net> <20050622112448.03594652.klappnase@web.de> Message-ID: <20050622125407.GA15013@unpythonic.net> My system is: Fedora Core 2 python-2.3.3-6 tk-8.4.5-8 I wrote the following program, in which a worker thread writes to a pipe which is read by the main thread by a handler that was created by 't.tk.createfilehandler()'. The program seems to work as expected, except that the thread usually terminates with an "OSError: Broken pipe" exception rather than gracefully. Jeff #------------------------------------------------------------------------ import sys, Tkinter, threading, os, time exit_threads = False reader, writer = os.pipe() class Worker(threading.Thread): def run(self): while not exit_threads: time.sleep(1) os.write(writer, "working\n") os.close(writer) def read(*args): data = os.read(reader, 1024) tx.insert(Tkinter.END, "%10s: %s" % (time.time(), data)) tx.see(Tkinter.END) Worker().start() t = Tkinter.Tk() tx = Tkinter.Text(t); tx.pack() t.tk.createfilehandler(reader, Tkinter.READABLE, read) try: t.mainloop() finally: exit_threads = True os.close(reader) #------------------------------------------------------------------------ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050622/c23084e3/attachment.pgp From t.lericos at comcast.net Thu Jun 30 06:50:44 2005 From: t.lericos at comcast.net (Todd Lericos) Date: Wed, 29 Jun 2005 21:50:44 -0700 Subject: [Tkinter-discuss] canvas.create_image Message-ID: <42C37A24.4080206@comcast.net> Hello all, I'm new to the list and to Python. It has been tough going, but alot of fun. Here is my problem. I am trying to display an image on canvas. I was searching to the list for similar problems. It does seem to be a common problem. I tried many of the suggested fixes. For example, heading off garbage collection of the image...etc. No dice. Can someone take a look at the code and let me know if they see any pitfalls I am stepping in. Thanks in advance for any help rendered. Todd P.S. Please not the program in not complete yet. Thus some variables passed to MakeGui go nowhere. I know this already. #!/usr/local/python/bin/python import os, sys, string import pickle, time from Tkinter import * import Image class MakeGui: def __init__(self, tooltitle, filedir, filetype, plotelem, filelist): self.row = 0 # Creating the Window and Row/Column stuff self.root = root = Tk() root.minsize(300,200) root.rowconfigure(0, weight=1) root.columnconfigure(0,weight=1) root.columnconfigure(1,weight=2) # Creating the Title Label Label(root, text=tooltitle, font='bold').grid(columnspan=2) self.row = self.row + 1 #Create the Canvas self.tfile = filedir + 'image.' + filetype print self.tfile self.Image = PhotoImage(file = self.tfile) self.canvas = Canvas(root, width=508, height=509) self.canvas.create_image(250, 250, image = self.Image) self.canvas.grid(columnspan=2) self.row = self.row + 1 tooltitle = 'Lightning Climatology Viewer' filedir = '/data/local/ltgdata/images/' filetype = 'gif' plotelem = ['500mb Map','Lightning Z','Lightning FWZ','Month Stats'] filelist =[("Type 1", "U01"), ("Type 2", "U02"), ("Type 3", "U03"), ("Type 4", "U04"), ("Type 5", "U05"), ("Type 6", "U06"), ("Type 7", "U07"), ("Type 8", "U08"), ("Type 9", "U09"), ("Type 10", "U10"), ("Type 11", "U11"), ("Type 12", "U12"), ("Type 13", "U13"), ] MakeGui(tooltitle, filedir, filetype, plotelem, filelist) mainloop() From jepler at unpythonic.net Thu Jun 30 16:59:33 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 30 Jun 2005 09:59:33 -0500 Subject: [Tkinter-discuss] canvas.create_image In-Reply-To: <42C37A24.4080206@comcast.net> References: <42C37A24.4080206@comcast.net> Message-ID: <20050630145932.GC7252@unpythonic.net> On Wed, Jun 29, 2005 at 09:50:44PM -0700, Todd Lericos wrote: > I tried many of the suggested fixes. For example, heading off > garbage collection of the image...etc. No dice. I'm pretty sure you didn't "head off garbage collection of the image". Here's why: You immediately discard the MakeGui instance you create, and it is the only thing which holds a reference to the image. Perhaps this change will make your program work: - MakeGui(tooltitle, filedir, filetype, plotelem, filelist) + gui = MakeGui(tooltitle, filedir, filetype, plotelem, filelist) In fact, in the program below, storing the 'App' instance is what makes the difference between a program that displays an image and one that doesn't. Jeff import Tkinter class App: def __init__(self, t): self.i = Tkinter.PhotoImage(file = "example.gif") c = Tkinter.Canvas(t, width=16, height=16); c.pack() c.create_image(0, 0, image = self.i, anchor=Tkinter.NW) t = Tkinter.Tk() # If this line is used, the program does not work #App(t) # If this line is used, the program works a = App(t) t.mainloop() -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050630/370af10a/attachment.pgp