repeat until keypressed

Poul Riis priisdk at gmail.com
Mon May 29 09:14:46 EDT 2017


In good old pascal there was this one-liner command:
repeat until keypressed

Apparently there is no built-in analogue for that in python. I have explored several different possibilities (pyglet, keyboard, curses, ginput (from matplotlib) and others) but not managed to find anything that works the way I want.

In the following example I just want to replace 'waitforbuttonpress' with something like 'continueuntilbuttonpress' if such a command exists. It could be  a mouseclick or a keystroke from the terminal, for instance 'shift', 'space' or some character.

Poul Riis






import warnings
warnings.filterwarnings("ignore",".*GUI is implemented.*")
from pylab import *
ion()
plot1=subplot(2,1,1)
plot2=subplot(2,1,2)

for i in range(20):
    plot1.plot([20*(sin(i/10)+1)],[cos(i/10)],'bo')

    ### The following two lines should be replaced by
    ### something like "Go on until some key is pressed - then break"
    if plt.waitforbuttonpress():        
        break

    
    pause(0.1)
    draw()
for i in range(20):
    plot2.plot([20*(sin(i/10)+1)],[-cos(i/10)],'ro')
    pause(0.1)
    draw()
ioff()




More information about the Python-list mailing list