# Import the library for Marty to function and to connect the Raspberry Pi to Marty from martypy import Marty marty = Marty('exp', '/dev/ttyAMA0') # Import the library needed to bind keys to actions, for Marty import tkinter as tk # This prepares Marty for movement by properly aligning his legs and feet marty.get_ready() # Prepare an event object to assign actions to key presses def remote_key(event): # Use the values that are understood by the Tkinter library, convert any letter keystrokes to lowercase key_press = event.keysym.lower() # Carry out actions depending on the key pressed if key_press == 'w': print('Marty walks two steps forward') marty.walk() marty.stop('pause') # Create a window that will receive the keypress keys = tk.Tk() # Send the key to the remote_key function keys.bind_all('', remote_key) # Loop the remote_key function keys.mainloop()