From fredrik at pythonware.com Sat May 3 15:12:50 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 03 May 2008 15:12:50 +0200 Subject: [Tkinter-discuss] Listbox selection persistence In-Reply-To: <1209094745.15024.1249783713@webmail.messagingengine.com> References: <1209094745.15024.1249783713@webmail.messagingengine.com> Message-ID: leegold wrote: > But the x does not seem to persist outside of the > def selected() block. I want the final last button > press to persist so I can use those indexes for > further processing. What am I missing here? variables that are assigned inside a function are made local by default; to treat them otherwise, you need to flag them as global. see your favourite Python tutorial for details. From darr_low at yahoo.com Mon May 5 09:14:06 2008 From: darr_low at yahoo.com (Snakey) Date: Mon, 5 May 2008 00:14:06 -0700 (PDT) Subject: [Tkinter-discuss] how to get all the text from a text widget? Message-ID: <17053954.post@talk.nabble.com> I created a text widget to allow my users to enter some lines of text. Now I need to dump all the text contents into a string variable. How can i do that? -- View this message in context: http://www.nabble.com/how-to-get-all-the-text-from-a-text-widget--tp17053954p17053954.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From darr_low at yahoo.com Wed May 7 11:10:40 2008 From: darr_low at yahoo.com (Snakey) Date: Wed, 7 May 2008 02:10:40 -0700 (PDT) Subject: [Tkinter-discuss] how to import a module that is not in the work dir? Message-ID: <17100345.post@talk.nabble.com> I have written some functions in "my_functions.py". I need to use these functions in another program main.py. But, "my_functions.py" cannot reside in my local work folder. It resides in a shared directory somewhere else eg. in X:\shared\my_functions.py How can I import my_functions.py into main.py? Will this work: ? import X:\shared\my_functions.py -- View this message in context: http://www.nabble.com/how-to-import-a-module-that-is-not-in-the-work-dir--tp17100345p17100345.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From ggpolo at gmail.com Thu May 15 01:41:42 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 14 May 2008 23:41:42 +0000 (UTC) Subject: [Tkinter-discuss] how to get all the text from a text widget? References: <17053954.post@talk.nabble.com> Message-ID: Snakey yahoo.com> writes: > > > I created a text widget to allow my users to enter some lines of text. Now I > need to dump all the text contents into a string variable. How can i do > that? Supposing you have no tags, you could do: text.get('1.0', 'end') # text is your text widget The first parameter is the index1 specifying where to start looking for text, and the other parameter is the index2, where to stop looking for text (one before it). Lines are numbered from 1 and columns from 0, that is why I used '1.0' (which is accepted as an index), and 'end' is an special index which indicates the end of the text. From darr_low at yahoo.com Thu May 15 02:12:52 2008 From: darr_low at yahoo.com (Snakey) Date: Wed, 14 May 2008 17:12:52 -0700 (PDT) Subject: [Tkinter-discuss] how to get all the text from a text widget? In-Reply-To: References: <17053954.post@talk.nabble.com> Message-ID: <17243544.post@talk.nabble.com> Hi Polo, Thanks for the tip! Guilherme Polo wrote: > > Snakey yahoo.com> writes: > >> >> >> I created a text widget to allow my users to enter some lines of text. >> Now I >> need to dump all the text contents into a string variable. How can i do >> that? > > Supposing you have no tags, you could do: > > text.get('1.0', 'end') # text is your text widget > > The first parameter is the index1 specifying where to start looking for > text, > and the other parameter is the index2, where to stop looking for text (one > before it). Lines are numbered from 1 and columns from 0, that is why I > used > '1.0' (which is accepted as an index), and 'end' is an special index which > indicates the end of the text. > > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -- View this message in context: http://www.nabble.com/how-to-get-all-the-text-from-a-text-widget--tp17053954p17243544.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From ggpolo at gmail.com Thu May 15 02:17:51 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 14 May 2008 21:17:51 -0300 Subject: [Tkinter-discuss] [ANN] Ttk wrapper 0.0.9 Message-ID: Hello, Over the last weeks I've been doing a ttk wrapper as part of my GSoC project and now I feel that I can announce it in hope some people start using it. What is Ttk ? This wrapper provides classes to allow using the Tk themed widget set, which has been included in Tk 8.5 but can be used with earlier versions if you have Tile installed. Ttk is based on a revised and enhanced version of TIP #48 (http://tip.tcl.tk/48) specified style engine. Its basic idea is to separate, to the extent possible, the code implementing a widget's behavior from the code implementing its appearance. Widget class bindings are primarily responsible for maintaining the widget state and invoking callbacks, all aspects of the widgets appearance lies at Themes. Wrapper status I expect all the Ttk functionality to be available through this wrapper, but I have said this some days ago as well and found out some examples which failed to work and then I corrected the code. I guess I will only be 100% sure of this after people start using it and reporting problems, if there is some interest on this I can create a project at code.google.com to serve this purpose. The wrapper comes with some samples and documentation too, which can be improved a lot too, specially if people fail to use the wrapper, try to use the docs and fail again and then report how they failed. Getting it Right now you have to use svn to download the wrapper: svn co http://svn.python.org/projects/sandbox/trunk/ttk-gsoc Alternatively, for Python 2.x you can download this file (access the link and click on download): http://svn.python.org/view/sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py?rev=63254&view=markup Also, there is a site with some info regarding this project at: http://gpolo.ath.cx:81/projects/ttk_to_tkinter/ Regards, -- -- Guilherme H. Polo Goncalves From gaedol at gmail.com Wed May 21 12:49:22 2008 From: gaedol at gmail.com (Marco) Date: Wed, 21 May 2008 12:49:22 +0200 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() Message-ID: Hi all, I am quite new to tkinter programming, and i have a question. I am writing a "monitor": basically it reads a file on the filesystem and reports it in a graphical way using python and tkinter. Now the file, over time, changes, so once called root.mainloop() i'd need to reread the file, update the objects in memory and redraw the tkinter main window. How can I achieve that? Ideas? Suggestions? Is my approach wrong? Thanks, marco From ggpolo at gmail.com Wed May 21 14:01:34 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 21 May 2008 09:01:34 -0300 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() In-Reply-To: References: Message-ID: 2008/5/21 Marco : > Hi all, > > I am quite new to tkinter programming, and i have a question. > > I am writing a "monitor": basically it reads a file on the filesystem > and reports it in a graphical way using python and tkinter. > > Now the file, over time, changes, so once called root.mainloop() i'd > need to reread the file, update the objects in memory and redraw the > tkinter main window. > > How can I achieve that? Ideas? Suggestions? Is my approach wrong? You could check from time to time using after(ms, callback). After your callback is called, you have to re-eschedule the check, using after(ms, callback) again. If you don't want to depend on tcl for this, you could use inotify (pyinotify) if you are using Linux. > > Thanks, > > marco > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -- -- Guilherme H. Polo Goncalves From Cameron at phaseit.net Thu May 22 00:59:48 2008 From: Cameron at phaseit.net (Cameron Laird) Date: Wed, 21 May 2008 22:59:48 +0000 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() In-Reply-To: References: Message-ID: <20080521225948.GB11841@lairds.us> On Wed, May 21, 2008 at 12:49:22PM +0200, Marco wrote: . . . > I am quite new to tkinter programming, and i have a question. > > I am writing a "monitor": basically it reads a file on the filesystem > and reports it in a graphical way using python and tkinter. > > Now the file, over time, changes, so once called root.mainloop() i'd > need to reread the file, update the objects in memory and redraw the > tkinter main window. > > How can I achieve that? Ideas? Suggestions? Is my approach wrong? . . . Poll with after(). Fredrik's references, among others, explain this. I'll be tied up for a day; if you don't work out the details on your own, I'll return to explain. From peter.milliken at gmail.com Fri May 23 01:10:48 2008 From: peter.milliken at gmail.com (Peter Milliken) Date: Fri, 23 May 2008 09:10:48 +1000 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() In-Reply-To: <20080521225948.GB11841@lairds.us> References: <20080521225948.GB11841@lairds.us> Message-ID: <791153ba0805221610u43e3154bj7cad11cf5642e6b9@mail.gmail.com> in the time module, look at a function called sleep - arguments are 1 second intervals from memory i.e. something like this: import time while True: time.sleep(5) -- delay for 5 seconds before resuming loop On Thu, May 22, 2008 at 8:59 AM, Cameron Laird wrote: > On Wed, May 21, 2008 at 12:49:22PM +0200, Marco wrote: > . > . > . > > I am quite new to tkinter programming, and i have a question. > > > > I am writing a "monitor": basically it reads a file on the filesystem > > and reports it in a graphical way using python and tkinter. > > > > Now the file, over time, changes, so once called root.mainloop() i'd > > need to reread the file, update the objects in memory and redraw the > > tkinter main window. > > > > How can I achieve that? Ideas? Suggestions? Is my approach wrong? > . > . > . > Poll with after(). Fredrik's references, among others, > explain this. I'll be tied up for a day; if you don't > work out the details on your own, I'll return to explain. > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Cameron at phaseit.net Fri May 23 01:49:25 2008 From: Cameron at phaseit.net (Cameron Laird) Date: Thu, 22 May 2008 23:49:25 +0000 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() In-Reply-To: <791153ba0805221610u43e3154bj7cad11cf5642e6b9@mail.gmail.com> References: <20080521225948.GB11841@lairds.us> <791153ba0805221610u43e3154bj7cad11cf5642e6b9@mail.gmail.com> Message-ID: <20080522234925.GA32187@lairds.us> On Fri, May 23, 2008 at 09:10:48AM +1000, Peter Milliken wrote: . . . > in the time module, look at a function called sleep - arguments are 1 second > intervals from memory i.e. something like this: > > import time > > while True: > > > time.sleep(5) -- delay for 5 seconds before resuming loop > > > > > On Thu, May 22, 2008 at 8:59 AM, Cameron Laird wrote: > > > On Wed, May 21, 2008 at 12:49:22PM +0200, Marco wrote: > > . > > . > > . > > > I am quite new to tkinter programming, and i have a question. > > > > > > I am writing a "monitor": basically it reads a file on the filesystem > > > and reports it in a graphical way using python and tkinter. > > > > > > Now the file, over time, changes, so once called root.mainloop() i'd > > > need to reread the file, update the objects in memory and redraw the > > > tkinter main window. > > > > > > How can I achieve that? Ideas? Suggestions? Is my approach wrong? > > . > > . > > . > > Poll with after(). Fredrik's references, among others, > > explain this. I'll be tied up for a day; if you don't > > work out the details on your own, I'll return to explain. . . . Peter, while I agree that time.sleep() can serve to construct a quick model of a polling operation, it often leads to dissatisfaction because, in contrast to after()-based implementations, it "freezes" the Tkinter windows while sleep()ing. From gaedol at gmail.com Fri May 23 12:26:12 2008 From: gaedol at gmail.com (Marco) Date: Fri, 23 May 2008 12:26:12 +0200 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() In-Reply-To: <20080522234925.GA32187@lairds.us> References: <20080521225948.GB11841@lairds.us> <791153ba0805221610u43e3154bj7cad11cf5642e6b9@mail.gmail.com> <20080522234925.GA32187@lairds.us> Message-ID: Hi all, and thanks for the answers: how, i avoided the sleep() approach, because, as Cameron said i supposed that it freezed the application: being in sleep() it stops the mainloop()... Now, i have used the after() approach, with some satisfactory results, only, there is something that still bugs me: if i understand correctly after() tells the loop to execute someething after some time (in milliseconds). What i'd like to do is something more like every()... In fact, i'd like the application to be redrawn every() second (so to say), while, if i understand correctly, every time i want to redraw the application (for example because in the meantime the log i'm monitoring has changed) i have to call after(). In this sense i have put an after() at the end of every possible event that the user, while working on the interface, could do. But, if nothing happens at the GUI level, then nothing is updated. I'd prefer to avoid to put a "UPDATE" button on the app, but as of now, seems like it's the only way to do it safely. I am wrong? thanks again, marco On Fri, May 23, 2008 at 1:49 AM, Cameron Laird wrote: > On Fri, May 23, 2008 at 09:10:48AM +1000, Peter Milliken wrote: > . > . > . >> in the time module, look at a function called sleep - arguments are 1 second >> intervals from memory i.e. something like this: >> >> import time >> >> while True: >> >> >> time.sleep(5) -- delay for 5 seconds before resuming loop >> >> >> >> >> On Thu, May 22, 2008 at 8:59 AM, Cameron Laird wrote: >> >> > On Wed, May 21, 2008 at 12:49:22PM +0200, Marco wrote: >> > . >> > . >> > . >> > > I am quite new to tkinter programming, and i have a question. >> > > >> > > I am writing a "monitor": basically it reads a file on the filesystem >> > > and reports it in a graphical way using python and tkinter. >> > > >> > > Now the file, over time, changes, so once called root.mainloop() i'd >> > > need to reread the file, update the objects in memory and redraw the >> > > tkinter main window. >> > > >> > > How can I achieve that? Ideas? Suggestions? Is my approach wrong? >> > . >> > . >> > . >> > Poll with after(). Fredrik's references, among others, >> > explain this. I'll be tied up for a day; if you don't >> > work out the details on your own, I'll return to explain. > . > . > . > Peter, while I agree that time.sleep() can serve to > construct a quick model of a polling operation, it > often leads to dissatisfaction because, in contrast > to after()-based implementations, it "freezes" the > Tkinter windows while sleep()ing. > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From Cameron at phaseit.net Fri May 23 16:52:44 2008 From: Cameron at phaseit.net (Cameron Laird) Date: Fri, 23 May 2008 14:52:44 +0000 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() In-Reply-To: References: <20080521225948.GB11841@lairds.us> <791153ba0805221610u43e3154bj7cad11cf5642e6b9@mail.gmail.com> <20080522234925.GA32187@lairds.us> Message-ID: <20080523145244.GA10078@lairds.us> On Fri, May 23, 2008 at 12:26:12PM +0200, Marco wrote: . . . > and thanks for the answers: how, i avoided the sleep() approach, > because, as Cameron said i supposed that it freezed the application: > being in sleep() it stops the mainloop()... > > Now, > > i have used the after() approach, with some satisfactory results, > only, there is something that still bugs me: if i understand correctly > after() tells the loop to execute someething after some time (in > milliseconds). What i'd like to do is something more like every()... > In fact, i'd like the application to be redrawn every() second (so to > say), while, if i understand correctly, every time i want to redraw > the application (for example because in the meantime the log i'm > monitoring has changed) i have to call after(). In this sense i have > put an after() at the end of every possible event that the user, while > working on the interface, could do. But, if nothing happens at the GUI > level, then nothing is updated. > > I'd prefer to avoid to put a "UPDATE" button on the app, but as of > now, seems like it's the only way to do it safely. > > I am wrong? . . . Yes and no. every() is a common need among Tkinter() programmers, for all the reasons you describe. I'm sure several of us have written our own version, but, to my surprise--astonishment!--I can't put my hands on one of them in public space just now. I'm late for a meeting myself; I'll summarize: A. You do NOT need to have after()s all over the widget tree, although I can understand the confusion; B. All that's necessary is a single "free-running" after() *that invokes itself*; and C. After I get out of my meetings, I'll write an example. From Cameron at phaseit.net Sun May 25 22:00:26 2008 From: Cameron at phaseit.net (Cameron Laird) Date: Sun, 25 May 2008 20:00:26 +0000 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() In-Reply-To: <20080523145244.GA10078@lairds.us> References: <20080521225948.GB11841@lairds.us> <791153ba0805221610u43e3154bj7cad11cf5642e6b9@mail.gmail.com> <20080522234925.GA32187@lairds.us> <20080523145244.GA10078@lairds.us> Message-ID: <20080525200026.GA1636@lairds.us> On Fri, May 23, 2008 at 02:52:44PM +0000, Cameron Laird wrote: > . > . > . > > and thanks for the answers: how, i avoided the sleep() approach, > > because, as Cameron said i supposed that it freezed the application: > > being in sleep() it stops the mainloop()... > > > > Now, > > > > i have used the after() approach, with some satisfactory results, > > only, there is something that still bugs me: if i understand correctly > > after() tells the loop to execute someething after some time (in > > milliseconds). What i'd like to do is something more like every()... > > In fact, i'd like the application to be redrawn every() second (so to > > say), while, if i understand correctly, every time i want to redraw > > the application (for example because in the meantime the log i'm > > monitoring has changed) i have to call after(). In this sense i have > > put an after() at the end of every possible event that the user, while > > working on the interface, could do. But, if nothing happens at the GUI > > level, then nothing is updated. > > > > I'd prefer to avoid to put a "UPDATE" button on the app, but as of > > now, seems like it's the only way to do it safely. > > > > I am wrong? > . > . > . > Yes and no. > > every() is a common need among Tkinter() programmers, > for all the reasons you describe. I'm sure several > of us have written our own version, but, to my > surprise--astonishment!--I can't put my hands on one > of them in public space just now. > > I'm late for a meeting myself; I'll summarize: > A. You do NOT need to have after()s all > over the widget tree, although I can > understand the confusion; > B. All that's necessary is a single > "free-running" after() *that > invokes itself*; and > C. After I get out of my meetings, I'll > write an example. . . . I need to put this minimal example of after()-based polling in the Wiki ... import Tkinter import time root = Tkinter.Tk() def my_update(): display.set("The time now is '%s'." % time.asctime(time.localtime())) # Re-invoke myself in two seconds. root.after(2000, my_update) display = Tkinter.StringVar() window = Tkinter.Label(root, textvariable = display) window.pack() my_update() root.mainloop() The effect is to create a textual clock which updates every two seconds, while keeping the window "live". From peter.milliken at gmail.com Mon May 26 03:29:40 2008 From: peter.milliken at gmail.com (Peter Milliken) Date: Mon, 26 May 2008 11:29:40 +1000 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() In-Reply-To: <20080525200026.GA1636@lairds.us> References: <20080521225948.GB11841@lairds.us> <791153ba0805221610u43e3154bj7cad11cf5642e6b9@mail.gmail.com> <20080522234925.GA32187@lairds.us> <20080523145244.GA10078@lairds.us> <20080525200026.GA1636@lairds.us> Message-ID: <791153ba0805251829h15b30071x15f61a8f29892069@mail.gmail.com> True, sleep() pauses the main app - if you run it there. It wasn't obvious to me from the original question that this might be a problem :-) In my application (a simple egg timer that allows on the fly creation of new timers and allows timing in relative or absolute terms i.e. in 5 minutes 23 seconds alert me or at 10:06:55 alert me) I leave the sleep() call down in the thread that I created for each timer - so each "timer" thread pauses for X seconds (1 second in my case because that is the smallest increment of time that I am interested in). I use Pmw for all my GUI work - after getting your mind around how flexible it can be, you can create some amazingly power applications that can reconfigure themselves on the fly for the user - one of the best programming interfaces I have ever used! The guy who did this has my complete admiration! :-) Perhaps (just for fun :-)) think about recreating your application using threads and (message) queues to pass information between the main Tk loop and the various threads that you create. Be careful - Tkinter in not re-entrant and you need to leave all of your graphics manipulations in the mainloop - but you can safely do all sorts of other stuff (checking files for changes etc etc) in threads - as long as they don't do any GUI work then you are safe. Doing threaded applications in Tk is definitely not for the beginner - you can find cookbook examples of using threading with Tk. Personally I find it kind of fun to do - I work in real-time embedded systems programming, so threading and tasking is very familiar territory. But if you ever want to expand your horizons give it some thought - but be mindful that it requires a different mindset to that of straight "linear" thinking programming - many programmers have some difficulty when they are first exposed to threads and multi-tasking applications - but once you get past that barrier you start to think in those terms with ease :-) Peter On Mon, May 26, 2008 at 6:00 AM, Cameron Laird wrote: > On Fri, May 23, 2008 at 02:52:44PM +0000, Cameron Laird wrote: > > . > > . > > . > > > and thanks for the answers: how, i avoided the sleep() approach, > > > because, as Cameron said i supposed that it freezed the application: > > > being in sleep() it stops the mainloop()... > > > > > > Now, > > > > > > i have used the after() approach, with some satisfactory results, > > > only, there is something that still bugs me: if i understand correctly > > > after() tells the loop to execute someething after some time (in > > > milliseconds). What i'd like to do is something more like every()... > > > In fact, i'd like the application to be redrawn every() second (so to > > > say), while, if i understand correctly, every time i want to redraw > > > the application (for example because in the meantime the log i'm > > > monitoring has changed) i have to call after(). In this sense i have > > > put an after() at the end of every possible event that the user, while > > > working on the interface, could do. But, if nothing happens at the GUI > > > level, then nothing is updated. > > > > > > I'd prefer to avoid to put a "UPDATE" button on the app, but as of > > > now, seems like it's the only way to do it safely. > > > > > > I am wrong? > > . > > . > > . > > Yes and no. > > > > every() is a common need among Tkinter() programmers, > > for all the reasons you describe. I'm sure several > > of us have written our own version, but, to my > > surprise--astonishment!--I can't put my hands on one > > of them in public space just now. > > > > I'm late for a meeting myself; I'll summarize: > > A. You do NOT need to have after()s all > > over the widget tree, although I can > > understand the confusion; > > B. All that's necessary is a single > > "free-running" after() *that > > invokes itself*; and > > C. After I get out of my meetings, I'll > > write an example. > . > . > . > I need to put this minimal example of after()-based polling in the Wiki ... > > import Tkinter > import time > > root = Tkinter.Tk() > > def my_update(): > display.set("The time now is '%s'." % time.asctime(time.localtime())) > # Re-invoke myself in two seconds. > root.after(2000, my_update) > > display = Tkinter.StringVar() > window = Tkinter.Label(root, textvariable = display) > window.pack() > my_update() > root.mainloop() > > The effect is to create a textual clock which updates every two seconds, > while keeping the window "live". > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Cameron at phaseit.net Mon May 26 16:13:05 2008 From: Cameron at phaseit.net (Cameron Laird) Date: Mon, 26 May 2008 14:13:05 +0000 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() In-Reply-To: <791153ba0805251829h15b30071x15f61a8f29892069@mail.gmail.com> References: <20080521225948.GB11841@lairds.us> <791153ba0805221610u43e3154bj7cad11cf5642e6b9@mail.gmail.com> <20080522234925.GA32187@lairds.us> <20080523145244.GA10078@lairds.us> <20080525200026.GA1636@lairds.us> <791153ba0805251829h15b30071x15f61a8f29892069@mail.gmail.com> Message-ID: <20080526141304.GA7773@lairds.us> On Mon, May 26, 2008 at 11:29:40AM +1000, Peter Milliken wrote: . . . > True, sleep() pauses the main app - if you run it there. It wasn't obvious > to me from the original question that this might be a problem :-) > > In my application (a simple egg timer that allows on the fly creation of new > timers and allows timing in relative or absolute terms i.e. in 5 minutes 23 > seconds alert me or at 10:06:55 alert me) I leave the sleep() call down in > the thread that I created for each timer - so each "timer" thread pauses for > X seconds (1 second in my case because that is the smallest increment of > time that I am interested in). > > I use Pmw for all my GUI work - after getting your mind around how flexible > it can be, you can create some amazingly power applications that can > reconfigure themselves on the fly for the user - one of the best programming > interfaces I have ever used! The guy who did this has my complete > admiration! :-) > > Perhaps (just for fun :-)) think about recreating your application using > threads and (message) queues to pass information between the main Tk loop > and the various threads that you create. > > Be careful - Tkinter in not re-entrant and you need to leave all of your > graphics manipulations in the mainloop - but you can safely do all sorts of > other stuff (checking files for changes etc etc) in threads - as long as > they don't do any GUI work then you are safe. > > Doing threaded applications in Tk is definitely not for the beginner - you > can find cookbook examples of using threading with Tk. > > Personally I find it kind of fun to do - I work in real-time embedded > systems programming, so threading and tasking is very familiar territory. > But if you ever want to expand your horizons give it some thought - but be > mindful that it requires a different mindset to that of straight "linear" > thinking programming - many programmers have some difficulty when they are > first exposed to threads and multi-tasking applications - but once you get > past that barrier you start to think in those terms with ease :-) > > > . > > > . > > > . > > > > and thanks for the answers: how, i avoided the sleep() approach, > > > > because, as Cameron said i supposed that it freezed the application: > > > > being in sleep() it stops the mainloop()... > > . > > . > > . > > I need to put this minimal example of after()-based polling in the Wiki ... > > > > import Tkinter > > import time > > > > root = Tkinter.Tk() > > > > def my_update(): > > display.set("The time now is '%s'." % time.asctime(time.localtime())) > > # Re-invoke myself in two seconds. > > root.after(2000, my_update) > > > > display = Tkinter.StringVar() > > window = Tkinter.Label(root, textvariable = display) > > window.pack() > > my_update() > > root.mainloop() . . . I think we're all together now. To be certain, I'll say some of this in my own words. sleep() is not a "problem", but it frequently is a *surprise* to those working in this area for the first time. Concurrency is indeed distinct from sequential- procedural patterns, and I agree that folklore tells us many newcomers to the area take a bit of time to adjust. I'd add that, to the best of my knowledge, that adjustment is present whether coding is in a thread-based or event-based idiom. While I'm also a firm believer that the latter is less error-prone for many common requirement sets, I agree that Pmw is a considerable value for which we all should be thankful. You're absolutely right that Tkinter (and X-windows- compatible toolkits, more generally) need to keep their GUIs in a single thread. Is it handy for you to share a threaded-Pmw-based equi- valent of the two-second-grainy clock I've included above? I think it'll make for an interesting comparison from which we perhaps might all learn. If you don't get to it in the next week, I'll try, although I'm rusty with Pmw. From peter.milliken at gmail.com Tue May 27 00:09:37 2008 From: peter.milliken at gmail.com (Peter Milliken) Date: Tue, 27 May 2008 08:09:37 +1000 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() In-Reply-To: <20080526141304.GA7773@lairds.us> References: <20080521225948.GB11841@lairds.us> <791153ba0805221610u43e3154bj7cad11cf5642e6b9@mail.gmail.com> <20080522234925.GA32187@lairds.us> <20080523145244.GA10078@lairds.us> <20080525200026.GA1636@lairds.us> <791153ba0805251829h15b30071x15f61a8f29892069@mail.gmail.com> <20080526141304.GA7773@lairds.us> Message-ID: <791153ba0805261509r23c1ff89ke9de53ee73a2a2e7@mail.gmail.com> Mate, I am happy to share the entire messy thing if you like :-) What I have is the timer/thread thing but also how I have used Pmw to create an adaptive interface to the user (timers can be created or deleted as required and the GUI just resizes/remaps everything). Since it was never written to be read/understood by others, I am not sure how good the code is to understand/read. It's probably not too bad, because even for my own stuff I tend to write comments (never have believed in "self-documenting code" :-)). But I doubt that it will have good enough comments for somebody who hasn't seen Pmw or threads before to necessarily work out what is happening. But I am more than happy to post the entire thing somewhere - where is a good place to post it? Peter On Tue, May 27, 2008 at 12:13 AM, Cameron Laird wrote: > On Mon, May 26, 2008 at 11:29:40AM +1000, Peter Milliken wrote: > . > . > . > > True, sleep() pauses the main app - if you run it there. It wasn't > obvious > > to me from the original question that this might be a problem :-) > > > > In my application (a simple egg timer that allows on the fly creation of > new > > timers and allows timing in relative or absolute terms i.e. in 5 minutes > 23 > > seconds alert me or at 10:06:55 alert me) I leave the sleep() call down > in > > the thread that I created for each timer - so each "timer" thread pauses > for > > X seconds (1 second in my case because that is the smallest increment of > > time that I am interested in). > > > > I use Pmw for all my GUI work - after getting your mind around how > flexible > > it can be, you can create some amazingly power applications that can > > reconfigure themselves on the fly for the user - one of the best > programming > > interfaces I have ever used! The guy who did this has my complete > > admiration! :-) > > > > Perhaps (just for fun :-)) think about recreating your application using > > threads and (message) queues to pass information between the main Tk loop > > and the various threads that you create. > > > > Be careful - Tkinter in not re-entrant and you need to leave all of your > > graphics manipulations in the mainloop - but you can safely do all sorts > of > > other stuff (checking files for changes etc etc) in threads - as long as > > they don't do any GUI work then you are safe. > > > > Doing threaded applications in Tk is definitely not for the beginner - > you > > can find cookbook examples of using threading with Tk. > > > > Personally I find it kind of fun to do - I work in real-time embedded > > systems programming, so threading and tasking is very familiar territory. > > But if you ever want to expand your horizons give it some thought - but > be > > mindful that it requires a different mindset to that of straight "linear" > > thinking programming - many programmers have some difficulty when they > are > > first exposed to threads and multi-tasking applications - but once you > get > > past that barrier you start to think in those terms with ease :-) > > > > . > > > > . > > > > . > > > > > and thanks for the answers: how, i avoided the sleep() approach, > > > > > because, as Cameron said i supposed that it freezed the > application: > > > > > being in sleep() it stops the mainloop()... > > > . > > > . > > > . > > > I need to put this minimal example of after()-based polling in the Wiki > ... > > > > > > import Tkinter > > > import time > > > > > > root = Tkinter.Tk() > > > > > > def my_update(): > > > display.set("The time now is '%s'." % > time.asctime(time.localtime())) > > > # Re-invoke myself in two seconds. > > > root.after(2000, my_update) > > > > > > display = Tkinter.StringVar() > > > window = Tkinter.Label(root, textvariable = display) > > > window.pack() > > > my_update() > > > root.mainloop() > . > . > . > I think we're all together now. To be certain, I'll > say some of this in my own words. > > sleep() is not a "problem", but it frequently is a > *surprise* to those working in this area for the first > time. Concurrency is indeed distinct from sequential- > procedural patterns, and I agree that folklore tells > us many newcomers to the area take a bit of time to > adjust. I'd add that, to the best of my knowledge, > that adjustment is present whether coding is in a > thread-based or event-based idiom. While I'm also a > firm believer that the latter is less error-prone for > many common requirement sets, I agree that Pmw is a > considerable value for which we all should be thankful. > > You're absolutely right that Tkinter (and X-windows- > compatible toolkits, more generally) need to keep their > GUIs in a single thread. > > Is it handy for you to share a threaded-Pmw-based equi- > valent of the two-second-grainy clock I've included > above? I think it'll make for an interesting comparison > from which we perhaps might all learn. If you don't get > to it in the next week, I'll try, although I'm rusty > with Pmw. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Cameron at phaseit.net Tue May 27 00:23:03 2008 From: Cameron at phaseit.net (Cameron Laird) Date: Mon, 26 May 2008 22:23:03 +0000 Subject: [Tkinter-discuss] tkinter "monitor" and root.mainloop() In-Reply-To: <791153ba0805261509r23c1ff89ke9de53ee73a2a2e7@mail.gmail.com> References: <20080521225948.GB11841@lairds.us> <791153ba0805221610u43e3154bj7cad11cf5642e6b9@mail.gmail.com> <20080522234925.GA32187@lairds.us> <20080523145244.GA10078@lairds.us> <20080525200026.GA1636@lairds.us> <791153ba0805251829h15b30071x15f61a8f29892069@mail.gmail.com> <20080526141304.GA7773@lairds.us> <791153ba0805261509r23c1ff89ke9de53ee73a2a2e7@mail.gmail.com> Message-ID: <20080526222303.GA22089@lairds.us> On Tue, May 27, 2008 at 08:09:37AM +1000, Peter Milliken wrote: . . . > What I have is the timer/thread thing but also how I have used Pmw to create > an adaptive interface to the user (timers can be created or deleted as > required and the GUI just resizes/remaps everything). > > Since it was never written to be read/understood by others, I am not sure > how good the code is to understand/read. It's probably not too bad, because > even for my own stuff I tend to write comments (never have believed in > "self-documenting code" :-)). But I doubt that it will have good enough > comments for somebody who hasn't seen Pmw or threads before to necessarily > work out what is happening. > > But I am more than happy to post the entire thing somewhere - where is a > good place to post it? . . . Let me get back to you by Wednesday on a good home for your example. In the meantime, I applaud your repeated mention of the potential for intelligence in Tkinter- and/or Pmw- based GUIs. I entirely agree: I'd be very unhappy making Visual Basic-style entry forms; a significant charm of Tkinter is the way it makes "adaptive GUIs" feasible, even easy. From ri at eeda.denso.co.jp Thu May 29 07:23:22 2008 From: ri at eeda.denso.co.jp (ri at eeda.denso.co.jp) Date: Thu, 29 May 2008 14:23:22 +0900 Subject: [Tkinter-discuss] How to get all the variables in a python shell Message-ID: <1D61C8BB5122A54798F01ABBFC3E613D071F23DF@eed8s05.eeda.denso.co.jp> Hi! I'm currently working on a scientific computation software built in python. What I want to implement is a Matlab style command window <-> workspace interaction. For example, you type 'a=1' in the command window, and you see a list item named 'a' in the workspace. You double click the icon of the item, and you see its value. You can modify the value of the list item, 1 -> 100 etc, after which if you go back to the command window and type 'a' and press enter, you see that varable a's value has been changed to 100. So my question is : if you have two DOS command windows running under WINDOWS OS, how can you make them share the same internal variable buffer? Or is there any easier way to implemente such kind of interaction? I'm looking forward to your answers. Thanks in advance! -------------- next part -------------- An HTML attachment was scrubbed... URL: