From alan.gauld at btinternet.com Sat May 14 12:56:44 2011 From: alan.gauld at btinternet.com (Alan Gauld) Date: Sat, 14 May 2011 11:56:44 +0100 Subject: [Tkinter-discuss] Python tutorial References: <9184B5BB5F0EE2438C877DF95AD93B510F80942CC2@MAILMBX03.MAIL.LA.GOV> Message-ID: "Steve Oldner" wrote > Interesting site, I like it. A different approach to writing > tutorials. > I did find it a bit hard to read the text on the pages, I completely agree on both counts. The contrast between the grey textured background and the dark text is not easy to read. Also the pages take a while to load fully, not sure what is going on to slow them down so much. It might just be the high number of nested div tags to be parsed. > but I was using IE8 and my eyes aren't that good any more. Using latest Firefox beta (and spectacles... :-) and a 4 year old PC! But with some clearer typography it has the makings of a good tutorial. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ From psaoflamand at live.com Wed May 18 17:01:06 2011 From: psaoflamand at live.com (psao pollard-flamand) Date: Wed, 18 May 2011 08:01:06 -0700 Subject: [Tkinter-discuss] Button Message-ID: You know when you click a tkinter button and the window usually freezes until its done? Does any one know how to stop that? Sent from my Windows Phone -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.odonnell at uam.es Wed May 18 18:08:03 2011 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Wed, 18 May 2011 18:08:03 +0200 Subject: [Tkinter-discuss] Button In-Reply-To: References: Message-ID: On Wed, May 18, 2011 at 5:01 PM, psao pollard-flamand wrote: > You know when you click a tkinter button and the window usually freezes > until its done? Does any one know how to stop that? This may or may not fix your problem, depending on your updating problem. Instead of: Button(tkwin, text="Go", command=dosomething) Put instead: def delayedDoSomething(): tkwin.after(100, dosomething) Button(tkwin, text="Go", command=delayedDoSomething) The net effect is taking your button command off the event queue for a bit, letting the button to redraw itself or whatever needs to be done. if the work done by the command invoked by the button is quite cpu intensive, I do somethink like the following: Class XXX(Toplevel): def updateInterface(self): self.updateDisplay() if not self.DONE: self.after(100, self.updateInterface) def doSomething(self): # A flag used by updateInterface to know when to quit self.DONE=False # The following will return, but call itself every second self.updateInterface() # Now do the work for fpath in glob.glob("*.*"): self.processFile(fpath) # next line is important I think to ensure the display proc gets a chance self.update() # work finished, tell updateInterface to quit self.DONE=True From peter.milliken at gmail.com Wed May 18 23:14:57 2011 From: peter.milliken at gmail.com (Peter Milliken) Date: Thu, 19 May 2011 07:14:57 +1000 Subject: [Tkinter-discuss] Button In-Reply-To: References: Message-ID: Michael offers excellent solutions. When the work being done is cpu intensive (and the application allows :-)), I often use threading i.e. the button runs a command that starts a Python thread which goes off and does what needs to be done. If the job being performed is that intensive then you probably want GUI elements to show progress - in which case you can communicate to the thread via pipes/queues and run another task that looks after the "communications" and is responsible for updating GUI elements - such as progress bars. I do this sort of thing a lot in my GUI's - just depends on what you are doing though. But threading isn't for everyone - if you are used to straight "linear" thinking in your programming then threads can take a bit of mind bending to get your head around - but once you have then all problems seem to be solved better through using threads :-) On Thu, May 19, 2011 at 2:08 AM, Michael O'Donnell wrote: > > > if the work done by the command invoked by the button is quite cpu > intensive, > I do somethink like the following: > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.odonnell at uam.es Thu May 19 00:28:24 2011 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Thu, 19 May 2011 00:28:24 +0200 Subject: [Tkinter-discuss] Button In-Reply-To: References: Message-ID: yes, Threading is the other solution. One needs to be very careful not to call any Tkinter elements from the child threads, as it seems this can cause freezes. I used threads for a while, but could not solve the odd cases where my interface froze until the child thread finished. In any case, see an example at: http://code.activestate.com/recipes/82965-threads-tkinter-and-asynchronous-io/ On Wed, May 18, 2011 at 11:14 PM, Peter Milliken wrote: > Michael offers excellent solutions. > When the work being done is cpu intensive (and the application allows :-)), > I often use threading i.e. the button runs a command that starts a Python > thread which goes off and does what needs to ?be done. > If the job being performed is that intensive then you probably want GUI > elements to show progress - in which case you can communicate to the thread > via pipes/queues and run another task that looks after the "communications" > and is responsible for updating GUI elements - such as progress bars. > I do this sort of thing a lot in my GUI's - just depends on what you are > doing though. But threading isn't for everyone - if you are used to straight > "linear" thinking in your programming then threads can take a bit of mind > bending to get your head around - but once you have then all problems seem > to be solved better through using threads :-) > > > On Thu, May 19, 2011 at 2:08 AM, Michael O'Donnell > wrote: >> >> > > >> >> if the work done by the command invoked by the button is quite cpu >> intensive, >> I do somethink like the following: >> >> > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > From peter.milliken at gmail.com Thu May 19 03:18:20 2011 From: peter.milliken at gmail.com (Peter Milliken) Date: Thu, 19 May 2011 11:18:20 +1000 Subject: [Tkinter-discuss] Button In-Reply-To: References: Message-ID: Do you use mtTkinter Michael? Best package since "sliced bread" (as the saying goes) - I haven't had any issues with GUI elements and tasking since using it. It has cured ALL of my issues with tasks and Tkinter GUI's freezing and behaving weirdly since I first discovered it. In my threads (checked my latest program), I just pass the progress bar as an argument to the thread - the argument is actually a class wrapper that "hides" the GUI progress bar from the thread program. So the thread performs the actual GUI updates directly. The class interface uses the same calls as a Queue provides - that way I can invoke the thread program from either a GUI or a command line interface - in the later case I use a Queue instance as the argument and have the command line part of the program read the data out and print it directly to the screen. I think that is all I do to get Tkinter and threads working together... Hope this makes sense :-) Peter On Thu, May 19, 2011 at 8:28 AM, Michael O'Donnell wrote: > yes, Threading is the other solution. > > One needs to be very careful not to call any Tkinter elements > from the child threads, as it seems this can cause freezes. > > I used threads for a while, but could not solve the odd cases > where my interface froze until the child thread finished. > > In any case, see an example at: > > > http://code.activestate.com/recipes/82965-threads-tkinter-and-asynchronous-io/ > > On Wed, May 18, 2011 at 11:14 PM, Peter Milliken > wrote: > > Michael offers excellent solutions. > > When the work being done is cpu intensive (and the application allows > :-)), > > I often use threading i.e. the button runs a command that starts a Python > > thread which goes off and does what needs to be done. > > If the job being performed is that intensive then you probably want GUI > > elements to show progress - in which case you can communicate to the > thread > > via pipes/queues and run another task that looks after the > "communications" > > and is responsible for updating GUI elements - such as progress bars. > > I do this sort of thing a lot in my GUI's - just depends on what you are > > doing though. But threading isn't for everyone - if you are used to > straight > > "linear" thinking in your programming then threads can take a bit of mind > > bending to get your head around - but once you have then all problems > seem > > to be solved better through using threads :-) > > > > > > On Thu, May 19, 2011 at 2:08 AM, Michael O'Donnell < > michael.odonnell at uam.es> > > wrote: > >> > >> > > > > > >> > >> if the work done by the command invoked by the button is quite cpu > >> intensive, > >> I do somethink like the following: > >> > >> > > > > _______________________________________________ > > 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 michael.odonnell at uam.es Thu May 19 08:27:33 2011 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Thu, 19 May 2011 08:27:33 +0200 Subject: [Tkinter-discuss] Button In-Reply-To: References: Message-ID: Hi Peter. I have somehow not sen mtTkinter before. Looks great, will try it out. Mick On Thu, May 19, 2011 at 3:18 AM, Peter Milliken wrote: > Do you use mtTkinter Michael? > Best package since "sliced bread" (as the saying goes) - I haven't had any > issues with GUI elements and tasking since using it. It has cured ALL of my > issues with tasks and Tkinter GUI's freezing and behaving weirdly since I > first discovered it. > In my threads (checked my latest program), I just pass the progress bar as > an argument to the thread - the argument is actually a class wrapper that > "hides" the GUI progress bar from the thread program. So the thread performs > the actual GUI updates directly. > The class interface uses the same calls as a Queue provides - that way I can > invoke the thread program from either a GUI or a command line interface - in > the later case I use a Queue instance as the argument and have the command > line part of the program read the data out and print it directly to the > screen. > I think that is all I do to get Tkinter and threads working together... > Hope this makes sense :-) > Peter > > On Thu, May 19, 2011 at 8:28 AM, Michael O'Donnell > wrote: >> >> yes, Threading is the other solution. >> >> One needs to be very careful not to call any Tkinter elements >> from the child threads, as it seems this can cause freezes. >> >> I used threads for a while, but could not solve the odd cases >> where my interface froze until the child thread finished. >> >> In any case, see an example at: >> >> >> http://code.activestate.com/recipes/82965-threads-tkinter-and-asynchronous-io/ >> >> On Wed, May 18, 2011 at 11:14 PM, Peter Milliken >> wrote: >> > Michael offers excellent solutions. >> > When the work being done is cpu intensive (and the application allows >> > :-)), >> > I often use threading i.e. the button runs a command that starts a >> > Python >> > thread which goes off and does what needs to ?be done. >> > If the job being performed is that intensive then you probably want GUI >> > elements to show progress - in which case you can communicate to the >> > thread >> > via pipes/queues and run another task that looks after the >> > "communications" >> > and is responsible for updating GUI elements - such as progress bars. >> > I do this sort of thing a lot in my GUI's - just depends on what you are >> > doing though. But threading isn't for everyone - if you are used to >> > straight >> > "linear" thinking in your programming then threads can take a bit of >> > mind >> > bending to get your head around - but once you have then all problems >> > seem >> > to be solved better through using threads :-) >> > >> > >> > On Thu, May 19, 2011 at 2:08 AM, Michael O'Donnell >> > >> > wrote: >> >> >> >> >> > >> > >> >> >> >> if the work done by the command invoked by the button is quite cpu >> >> intensive, >> >> I do somethink like the following: >> >> >> >> >> > >> > _______________________________________________ >> > Tkinter-discuss mailing list >> > Tkinter-discuss at python.org >> > http://mail.python.org/mailman/listinfo/tkinter-discuss >> > >> > > > From bob at mellowood.ca Sat May 21 02:27:40 2011 From: bob at mellowood.ca (Bob van der Poel) Date: Fri, 20 May 2011 17:27:40 -0700 Subject: [Tkinter-discuss] Callbacks to classes Message-ID: New to list ... hope it's not been covered before, and on topic .... Anyway, I've got a number of programs which suddenly stopped working. I think due to a change from python 2.6 to 2.7. I was setting up a menu call back to a Class with code like: Button(bf, text=txt, height=1, command=cmd).grid(column=c, row=0, pady=5) when 'cmd' was a simple class name. Doesn't work anymore :) However, if I change cmd to a lambda it's find. Sorry, this isn't a better (simple) example ... I'm pulling code out a non-trivial application I've been running for several years. But, most simply I'd have something like: Class foo: ... init, and present a options window, etc. --- set a call back to delete the window when done. Setting 'cmd' to 'foo' doesn't work anymore. However, cmd = lambda:foo() solves the issue. I'm thinking I've been doing it wrong all along? Best, -- **** Listen to my CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW:?? http://www.mellowood.ca From teh_sh_meister at yahoo.com Sat May 21 13:46:07 2011 From: teh_sh_meister at yahoo.com (Nemes Andrei) Date: Sat, 21 May 2011 12:46:07 +0100 (BST) Subject: [Tkinter-discuss] syntax highlighting Message-ID: <735039.42042.qm@web29107.mail.ird.yahoo.com> Hi! I was wondering if there is any auto-tag function in Tkinter. I want to make a simple syntax highlighter, and so far what I've done is bind a function to Key event and build a string with the registered keys, compare that to a list of special words and if they match, delete the word from the text and replace it with a tagged version on the same position. This did not work out very well because the key event and handlers are fired off on key press, therefore before the character is actually written in the text itself, resulting in the function deleting everything before the last letter is printed in the text; this results always in the last letter of the word remaining on screen (for example "doctype" = "doctypee"). How can I fix this? Is there a "KeyUp" event? Better yet, is there a nicer way to do syntax highlighting? Please advise. Here is the bit of code: self.edit.bind("", self.parent.key) ... ??? def key(self,event): ??????? if event.char == " ": ??????????? self.word="" ??????? if event.char == event.keysym: ??????????? self.word=self.word+event.char ??????????? self.match(self.word,"HTML") ??????????????????????? ??????? ??? def match(self,keyword,lang): ??????? match=False ??????? print keyword ??????? if lang=="HTML": ??????????? for item in self.html: ??????????????? if item==keyword: ?????????????????? match=True ?????????????????? break ??????? if match: ??????????? self.tab.editlist[self.tab.nav.index("current")].delete("insert-%s c" %len(keyword), "insert") ??????????? self.tab.editlist[self.tab.nav.index("current")].insert("insert", keyword, "blue") Thanks in advance! Regards, Andrei Nemes -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Sat May 21 15:14:22 2011 From: klappnase at web.de (Michael Lange) Date: Sat, 21 May 2011 15:14:22 +0200 Subject: [Tkinter-discuss] syntax highlighting In-Reply-To: <735039.42042.qm@web29107.mail.ird.yahoo.com> References: <735039.42042.qm@web29107.mail.ird.yahoo.com> Message-ID: <20110521151422.34bd5468.klappnase@web.de> Hi, Thus spoketh Nemes Andrei unto us on Sat, 21 May 2011 12:46:07 +0100 (BST): > Hi! > I was wondering if there is any auto-tag function in Tkinter. I want to > make a simple syntax highlighter, and so far what I've done is bind a > function to Key event and build a string with the registered keys, > compare that to a list of special words and if they match, delete the > word from the text and replace it with a tagged version on the same > position. This did not work out very well because the key event and > handlers are fired off on key press, therefore before the character is > actually written in the text itself, resulting in the function deleting > everything before the last letter is printed in the text; this results > always in the last letter of the word remaining on screen (for example > "doctype" = "doctypee"). > > How can I fix this? > > > Is there a "KeyUp" event? You would probably need "" . > > Better yet, is there a nicer way to do syntax highlighting? > Please advise. I would try to use some code from IDLE. If you run the demo from IDLE's ColorDelegator module you get a text widget that highlights python code. Depending on what exactly you want to achieve, it might be possible to change the keyword list and a few other things to customize it for your needs (I never tried this myself, though). Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. You can't evaluate a man by logic alone. -- McCoy, "I, Mudd", stardate 4513.3 From bob at mellowood.ca Sun May 22 02:22:22 2011 From: bob at mellowood.ca (Bob van der Poel) Date: Sat, 21 May 2011 17:22:22 -0700 Subject: [Tkinter-discuss] Callbacks to classes In-Reply-To: References: Message-ID: > Anyway, I've got a number of programs which suddenly stopped working. > I think due to a change from python 2.6 to 2.7. > > I was setting up a menu call back to a Class with code like: > > ? ?Button(bf, text=txt, height=1, command=cmd).grid(column=c, row=0, pady=5) > > when 'cmd' was a simple class name. Doesn't work anymore :) > > However, if I change cmd to a lambda it's find. I got some help over in comp.python on this. Apparently there was a change between 2.6 and 2.7. There are 3 easy solutions: 1. Use a function :) 2. Use lambda. 3. Use a new style class, ie: class mywindow(object) I've tried all three and they all work. I'm not sure what the best method is. Best to all. -- **** Listen to my CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW:?? http://www.mellowood.ca From alan.gauld at btinternet.com Mon May 23 10:18:19 2011 From: alan.gauld at btinternet.com (Alan Gauld) Date: Mon, 23 May 2011 09:18:19 +0100 Subject: [Tkinter-discuss] Button References: Message-ID: "psao pollard-flamand" wrote > You know when you click a tkinter button and the > window usually freezes until its done? Actually it doesn't *usually* freeze because most Tkinter apps are designed to prevent that :-) > Does any one know how to stop that? The key here is that GUI event handlers are intended to be short functions that do one thing at a time. If they have to do more intensive and time consuming actions then the event handler will either: a) launch another function to do that, using a different thread if necessary. b) open a modal dialog that displays progress (or at the very least a warning). The objective should be to habd control back to the event loop as fast as possible so you can respond to the next event - which might, after all, be a cancel operation! HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ From alan.gauld at btinternet.com Mon May 23 10:27:59 2011 From: alan.gauld at btinternet.com (Alan Gauld) Date: Mon, 23 May 2011 09:27:59 +0100 Subject: [Tkinter-discuss] Callbacks to classes References: Message-ID: "Bob van der Poel" wrote > > I was setting up a menu call back to a Class with code like: > > > > Button(bf, text=txt, height=1, command=cmd).grid(column=c, row=0, > > pady=5) > I got some help over in comp.python on this. Apparently there was a > change between 2.6 and 2.7. There are 3 easy solutions: > > 1. Use a function :) > 2. Use lambda. > 3. Use a new style class, ie: > I've tried all three and they all work. I'm not sure what the best > method is. Using a class is very unusual and has several drawbacks. The main one is that Tkinter calls the call-back object which in the case of a class creates a new instance. So you are constantly creating new objects to which you have no reference so cannot call their methods - which is a bit pointless! So any action you perform needs to be in the init method. You can do more with class callbacks if you store the objects somewhere, like a class variable or global list but its all very unusual and only used for special occasions such as rewinding history etc.. Using a functiion is good if you have the same code shared by many events or if it takes parameters, although in that case you also need... A lambda is probably the most common, especially when you really want to call another function. The lambda body just executes the function passing whatever parameters are required. So I'd say the normal case would be a combination of lambda and function and classes used very rarely, more or less only when persistent actions are required. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ From alan.gauld at btinternet.com Mon May 23 10:30:18 2011 From: alan.gauld at btinternet.com (Alan Gauld) Date: Mon, 23 May 2011 09:30:18 +0100 Subject: [Tkinter-discuss] syntax highlighting References: <735039.42042.qm@web29107.mail.ird.yahoo.com> Message-ID: "Nemes Andrei" wrote > Better yet, is there a nicer way to do syntax highlighting? Take a look at the IDLE source - it is all in Python/Tkinter and available in the standard distribution. It seems to handle syntax highlighting OK... HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ From greg.ewing at canterbury.ac.nz Mon May 23 23:44:15 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 24 May 2011 09:44:15 +1200 Subject: [Tkinter-discuss] Callbacks to classes In-Reply-To: References: Message-ID: <4DDAD52F.2070103@canterbury.ac.nz> Alan Gauld wrote: > Using a class is very unusual and has several drawbacks. > The main one is that Tkinter calls the call-back object which > in the case of a class creates a new instance. So you are > constantly creating new objects to which you have no > reference so cannot call their methods It's not useless if, as appears to be the case here, the class in question is implementing a modal dialog. On the contrary, I think it's actually rather elegant, if a bit surprising! -- Greg From bob at mellowood.ca Mon May 23 23:58:06 2011 From: bob at mellowood.ca (Bob van der Poel) Date: Mon, 23 May 2011 14:58:06 -0700 Subject: [Tkinter-discuss] Callbacks to classes In-Reply-To: <4DDAD52F.2070103@canterbury.ac.nz> References: <4DDAD52F.2070103@canterbury.ac.nz> Message-ID: > It's not useless if, as appears to be the case here, > the class in question is implementing a modal dialog. > On the contrary, I think it's actually rather elegant, > if a bit surprising! Thanks for confirming that I'm not completely out of my mind doing things this way :) Seriously, I'm sure it's not my idea! I just don't recall where I got the idea from. But, if you are interested in seeing the program it's available at: http://mellowood.ca/xpmidi/index.html Best, -- **** Listen to my CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW:?? http://www.mellowood.ca From psaoflamand at live.com Tue May 24 17:08:22 2011 From: psaoflamand at live.com (psao pollard-flamand) Date: Tue, 24 May 2011 08:08:22 -0700 Subject: [Tkinter-discuss] Why to use classes Message-ID: Hi I've been using classes for a while now but I don't really know what the advantage is as opposed to just having the code without the class. Anybody know? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjtrebat at gmail.com Tue May 24 20:08:41 2011 From: tjtrebat at gmail.com (Tom Trebat) Date: Tue, 24 May 2011 11:08:41 -0700 (PDT) Subject: [Tkinter-discuss] Tk Learning Page Message-ID: <31692655.post@talk.nabble.com> Hello all, I have created a page of sample TKinter projects that might be of good use to anybody learning Python and Tk. Please take a look at my page, and let me know what you think of my work. http://sites.google.com/site/pythonprojects0/ http://sites.google.com/site/pythonprojects0/ Thanks, Tom -- View this message in context: http://old.nabble.com/Tk-Learning-Page-tp31692655p31692655.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.