title: Jump to function when key is pressed
body: <p>I made some hardware for my Raspberry Pi's GPIO that I'd like to test. I found some neat python code that makes 8 buttons for the 8 outputs, and lets you toggle their state. I have almost no knowledge of python, but I'd like to be able to toggle the 8 outputs via keyboard (ex. numbers 1-8). I don't know how to ask for a keyboard input without pausing the flow of the program then continuing after response.</p>
  
  <p>How can I make the numbers 1-8 "interrupt" my program and jump to 1 of the 8 corresponding functions?</p>
  
  <p>My code:</p>
  
  <pre><code>from Tkinter import *
  import RPi.GPIO as GPIO
  import time
  
  GPIO.setmode( GPIO.BCM )
  GPIO.setup( 4, GPIO.OUT)
  GPIO.setup(17, GPIO.OUT)
  GPIO.setup(18, GPIO.OUT)
  GPIO.setup(21, GPIO.OUT)
  GPIO.setup(22, GPIO.OUT)
  GPIO.setup(23, GPIO.OUT)
  GPIO.setup(24, GPIO.OUT)
  GPIO.setup(25, GPIO.OUT)
  
  class App:
      io4=0
      io17=0
      io18=0
      io21=0
      io22=0
      io23=0
      io24=0
      io25=0
  
      def __init__(self, master):
  
          frame = Frame(master)
          frame.pack()
  
          self.p1 = Button(frame, text="GPIO 25",fg="green", command=self.gpio25)
          self.p1.pack(side=LEFT)
          self.p1.grid(row=0,column=0)
  
          self.p2 = Button(frame, text="GPIO 24",fg="red", command=self.gpio24)
          self.p2.pack(side=LEFT)
          self.p2.grid(row=0,column=1)
  
          self.p3 = Button(frame, text="GPIO 23",fg="red", command=self.gpio23)
          self.p3.pack(side=LEFT)
          self.p3.grid(row=0,column=2)
  
          self.p4 = Button(frame, text="GPIO 22",fg="red", command=self.gpio22)
          self.p4.pack(side=LEFT)
          self.p4.grid(row=0,column=3)
  
          self.p5 = Button(frame, text="GPIO 21",fg="red", command=self.gpio21)
          self.p5.pack(side=LEFT)
          self.p5.grid(row=0,column=4)
  
          self.p6 = Button(frame, text="GPIO 18",fg="red", command=self.gpio18)
          self.p6.pack(side=LEFT)
          self.p6.grid(row=0,column=5)
  
          self.p7 = Button(frame, text="GPIO 17",fg="red", command=self.gpio17)
          self.p7.pack(side=LEFT)
          self.p7.grid(row=0,column=6)
  
  
          self.p8 = Button(frame, text="GPIO 4", fg="red",command=self.gpio4)
          self.p8.pack(side=LEFT)
          self.p8.grid(row=0,column=7)
  
      def gpio4(self):
          if self.io4==0:
            GPIO.output(4, GPIO.HIGH)
            self.io4=1
          else:
            GPIO.output(4, GPIO.LOW)
            self.io4=0
          return
  
      def gpio17(self):
          if self.io17==0:
            GPIO.output(17, GPIO.HIGH)
            self.io17=1
          else:
            GPIO.output(17, GPIO.LOW)
            self.io17=0
          return
  
      def gpio18(self):
          if self.io18==0:
            GPIO.output(18, GPIO.HIGH)
            self.io18=1
          else:
            GPIO.output(18, GPIO.LOW)
            self.io18=0
          return
  
      def gpio21(self):
          if self.io21==0:
            GPIO.output(21, GPIO.HIGH)
            self.io21=1
          else:
            GPIO.output(21, GPIO.LOW)
            self.io21=0
          return
  
      def gpio22(self):
          if self.io22==0:
            GPIO.output(22, GPIO.HIGH)
            self.io22=1
          else:
            GPIO.output(22, GPIO.LOW)
            self.io22=0
          return
  
      def gpio23(self):
          if self.io23==0:
            GPIO.output(23, GPIO.HIGH)
            self.io23=1
          else:
            GPIO.output(23, GPIO.LOW)
            self.io23=0
          return
  
      def gpio24(self):
          if self.io24==0:
            GPIO.output(24, GPIO.HIGH)
            self.io24=1
          else:
            GPIO.output(24, GPIO.LOW)
            self.io24=0
          return
  
      def gpio25(self):
          if self.io25==0:
            GPIO.output(25, GPIO.HIGH)
            self.io25=1
          else:
            GPIO.output(25, GPIO.LOW)
            self.io25=0
          return
  
      def reserved(self):
          return
  
  root = Tk()
  app = App(root)
  root.mainloop()
  </code></pre>