how can I change what a script does while it is running, by pressing a key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • new to python
    New Member
    • Jul 2010
    • 4

    how can I change what a script does while it is running, by pressing a key

    I am trying to write code which will let the user press a key like 'b' and run an operation, while a script is still running, and have the script continue afterwards. How can I do this??? I am using Linux.
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    In a basic setup, something like
    Code:
    userAnswer=raw_input("Press 'b' or hit enter")
    if userAnswer=="b":
        #do whatever
    elif userAnswer=="":
        #do something else
    else:
        #do the default option
    Of course if you want to be a little fancier, you can put the raw_input into a loop and test whether the input is valid before continuing.

    If you want to do it like an application, then you need to get into the various GUIs. tkinter is pretty standard.

    Comment

    Working...