[Tutor] stop a loop after precise amount of time

2012-11-25 Thread Saad Javed
import time s = time.time() + 30 running = True while running: if time.time() == s: print 'yes' running = False This stops the loop after 30s but the program uses about 12% cpu. What would be a more efficient way to do this? (p.s. i'm on python 2.7.3) Saad

Re: [Tutor] Dynamic TKinter widgets?

2012-11-25 Thread Alan Gauld
On 25/11/12 03:16, Nathan wrote: What I'm trying to do now is add support for the card images. the problem is, the program supports multiple types of spreads (two, so far, are selectable), and they use different numbers of cards. It looks like I need a variable number of widgets to display

Re: [Tutor] stop a loop after precise amount of time

2012-11-25 Thread Steven D'Aprano
On 25/11/12 19:50, Saad Javed wrote: import time s = time.time() + 30 running = True while running: if time.time() == s: print 'yes' running = False This stops the loop after 30s but the program uses about 12% cpu. What would be a more efficient way to do this? (p.s. i'm on python 2.7.3)

Re: [Tutor] stop a loop after precise amount of time

2012-11-25 Thread Saad Javed
time.sleep(30) will pause the program for 30s. I want to the run the program for 30s. Saad ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] Listen for input while performing other tasks

2012-11-25 Thread Sean Carolan
I'm working on a python script that runs on a Raspberry Pi. The script detects when hardware buttons are pressed, and then runs functions based on that input. I want to be able to always listen for a button press, no matter what the script is doing at the current moment. When a button press is

Re: [Tutor] stop a loop after precise amount of time

2012-11-25 Thread Saad Javed
import time running = True while running: print 'yes' time.sleep(10) This will print 'yes' after every 10s. I want to print 'yes' for 10s, then quit. Saad ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] stop a loop after precise amount of time

2012-11-25 Thread Steven D'Aprano
On 25/11/12 22:01, Saad Javed wrote: time.sleep(30) will pause the program for 30s. I want to the run the program for 30s. Your first email did not make that clear. Please take more care to explain your question. stop = time.time() + 30 while time.time() stop: do_something_useful()

Re: [Tutor] stop a loop after precise amount of time

2012-11-25 Thread Peter Otten
Saad Javed wrote: import time running = True while running: print 'yes' time.sleep(10) This will print 'yes' after every 10s. I want to print 'yes' for 10s, then quit. Then combine the two techniques, the busy waiting loop with sleeping for a shorter amount of time: import

Re: [Tutor] Listen for input while performing other tasks

2012-11-25 Thread Steven D'Aprano
On 25/11/12 22:06, Sean Carolan wrote: I'm working on a python script that runs on a Raspberry Pi. The script detects when hardware buttons are pressed, and then runs functions based on that input. I want to be able to always listen for a button press, no matter what the script is doing at the

Re: [Tutor] Listen for input while performing other tasks

2012-11-25 Thread Steven D'Aprano
On 25/11/12 22:06, Sean Carolan wrote: I'm working on a python script that runs on a Raspberry Pi. The script detects when hardware buttons are pressed, and then runs functions based on that input. Oh I'm sorry, I completely misread what you wrote there. I didn't realise you were talking

Re: [Tutor] Listen for input while performing other tasks

2012-11-25 Thread Sean Carolan
If you show us how you check whether the button is pressed, we may be able to show you how to run that asynchronously. Apologies for the previous email; I think I sent it in HTML format. Gmail changed their user interface again... This is how I'm checking for a button press: modes = (weather,

Re: [Tutor] Listen for input while performing other tasks

2012-11-25 Thread Francois Dion
On Sun, Nov 25, 2012 at 7:32 AM, Sean Carolan scaro...@gmail.com wrote: This is how I'm checking for a button press: This should really be done with interrupts, but unfortunately there is no support in the RPi.GPIO module for that, even if you have a patched kernel. I've done a workshop earlier

Re: [Tutor] Listen for input while performing other tasks

2012-11-25 Thread Sean Carolan
On Sun, Nov 25, 2012 at 7:29 AM, Francois Dion francois.d...@gmail.com wrote: This should really be done with interrupts, but unfortunately there is no support in the RPi.GPIO module for that, even if you have a patched kernel. Thank you for all this great information. I ended up going with a

Re: [Tutor] Dynamic TKinter widgets?

2012-11-25 Thread ALAN GAULD
CC'ing the list...   I know you can use images instead of text with Labels, like you can with Buttons.  The advantage of a Text widget, in this case, is that you can use both in the same widget.  That way, I don't need to worry about how widgets are displayed, shuffled around, and  undisplayed

Re: [Tutor] Dynamic TKinter widgets?

2012-11-25 Thread Nathan
On Nov 25, 2012 6:49 PM, ALAN GAULD alan.ga...@btinternet.com wrote: CC'ing the list... Oops, my bad. I forget to hit Reply All. I know you can use images instead of text with Labels, like you can with Buttons. The advantage of a Text widget, in this case, is that you can use both in the