# Import the library for Marty to function and to connect the Raspberry Pi to Marty from martypy import Marty # Import the library needed to bind keys to actions, for Marty import tkinter as tk tk.geometry("400x400") marty = Marty('exp', '/dev/ttyAMA0') # This prepares Marty for movement by properly aligning his legs and feet marty.get_ready() # Prepare an event callback function associating actions with 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() # Create a window that will receive the keypress keys = tk.Tk() # Send the key to the remote_key function keys.bind_all('', remote_key) # Starts and loops remote_key function keys.mainloop()