Up GoPiGo Control Panel プログラム 作成: 2021-04-13
更新: 2021-04-13


#!/usr/bin/env python import tkinter from easygopigo3 import EasyGoPiGo3 egpg = EasyGoPiGo3() tki = tkinter.Tk() # window 設定 ################## # サイズ wx = 380 wy = 280 tki.geometry('{}x{}'.format(wx,wy)) # タイトル wttl = 'Control Panel' tki.title(wttl) # ボタン設定 ################## # サイズ bw = 10 bh = 1 # Stop b_name= 'Stop' def a_stop(): egpg.stop() b_stop = tkinter.Button(tki, text = b_name, width = bw, height = bh, bg='#ff0000', command = a_stop) bx = 130 by = 50 b_stop.place(x=bx, y=by) # Forward b_name = 'Forward' def a_forward(): egpg.set_speed(150) egpg.forward() b_forward = tkinter.Button(tki, text = b_name, width = bw, height = bh, command = a_forward) bx = 130 by = 20 b_forward.place(x=bx, y=by) # Back b_name = 'Back' def a_back(): egpg.set_speed(50) egpg.backward() b_back = tkinter.Button(tki, text = b_name, width = bw, height = bh, command = a_back) bx = 130 by = 80 b_back.place(x=bx, y=by) # Right b_name = 'Right' def a_right(): egpg.set_speed(50) egpg.right() b_right = tkinter.Button(tki, text = b_name, width = bw, height = bh, command = a_right) bx = 245 by = 50 b_right.place(x=bx, y=by) # Left b_name = 'Left' def a_left(): egpg.set_speed(50) egpg.left() b_left = tkinter.Button(tki, text = b_name, width = bw, height = bh, command = a_left) bx = 20 by = 50 b_left.place(x=bx, y=by) # Right LED b_name= 'Right LED' s_right_led = 0 def a_right_led(): global s_right_led if s_right_led == 0: s_right_led = 1 egpg.led_on(0) else: s_right_led = 0 egpg.led_off(0) b_right_led = tkinter.Button(tki, text = b_name, width = bw, height = bh, command = a_right_led) bx = 245 by = 130 b_right_led.place(x=bx, y=by) # Left LED b_name= 'Left LED' s_left_led = 0 def a_left_led(): global s_left_led if s_left_led == 0: s_left_led = 1 egpg.led_on(1) else: s_left_led = 0 egpg.led_off(1) b_left_led = tkinter.Button(tki, text = b_name, width = bw, height = bh, command = a_left_led) bx = 20 by = 130 b_left_led.place(x=bx, y=by) # Right eye b_name= 'Right eye' s_right_eye = 0 def a_right_eye(): global s_right_eye if s_right_eye == 0: s_right_eye = 1 egpg.open_right_eye() else: s_right_eye = 0 egpg.close_right_eye() b_right_eye = tkinter.Button(tki, text = b_name, width = bw, height = bh, command = a_right_eye) bx = 20 by = 170 b_right_eye.place(x=bx, y=by) # Left eye b_name = 'Left eye' s_left_eye = 0 def a_left_eye(): global s_left_eye if s_left_eye == 0: s_left_eye = 1 egpg.open_left_eye() else: s_left_eye = 0 egpg.close_left_eye() b_left_eye = tkinter.Button(tki, text = b_name, width = bw, height = bh, command = a_left_eye) bx = 245 by = 170 b_left_eye.place(x=bx, y=by) # Exit b_name = 'Exit' def a_exit(): egpg.stop() egpg.led_off(0) egpg.led_off(1) egpg.close_right_eye() egpg.close_left_eye() tki.destroy() b_exit = tkinter.Button(tki, text = b_name, width = bw, height = bh, command = a_exit) bx = 130 by = 220 b_exit.place(x=bx, y=by) # GoPiGo logo logo = tkinter.PhotoImage(file='logo.png') b_logo = tkinter.Button(tki, image = logo) bx = 140 by = 130 b_logo.place(x=bx, y=by) # window を表示 ########################################## tki.mainloop()

    $ vi panel.py

    $ chmod +x panel.py

    $ ./panel.py



GoPiGo 遠隔操作