I'm new to python and coding generally, so I'm a bit stuck on something where I need some guidance.
I'm currently working on a project from school, where I'm building a rc car with raspberry pi 3. Im currently working on a UI for the car in Tkinter. The code is below, what I am asking for is how I can make the car go forward, backward, left and right with clicking on the buttons from the GUI, and how to add push and release function on it.
As you can see I run it through remote GPIO (Gpiozero). Also, I'm just adding the left button here to have as an example of the rest of the code.
I have a photo image on the button, but if you want to run the code, just # it, and put in text instead inside tk.button
import tkinter as tk
import sys
from PIL import Image, ImageTk
import time
from gpiozero import motor
from gpiozero.pins.pigpio import PiGPIOFactory
#remote_factory = PiGPIOFactory(host=)
turn_speed = 0.5
drive_speed = 0.15
#remote_factory = PiGPIOFactory(host=)
# 19 = FORWARD, 13 = BACKWARD
motor_1 = Motor(forward=19, backward=13)
# 6 = LEFT, 5 = RIGHT
motor_2 = Motor(forward=6, backward=5)
drive_forward = motor_1.forward
drive_backward = motor_1.backward
turn_left = motor_2.forward
turn_right = motor_2.backward
#motor_forward = Motor(forward=19)
#motor_reverse = Motor(backward=13)
#motor_left = Motor(forward=6)
#motor_right = Motor(backward=5)
def main():
vindu=tk.Tk()
vindu.title("PiDrv")
vindu.geometry("300x300")
#vindu.configure
#Turn left
def left_arrow():
print("Left")
#turn_left
def stop():
print("Stop")
def left_button():
b = tk.Button(vindu, command=left_arrow )
b.grid(row=1, column=1, padx=0, pady=150)
image=ImageTk.PhotoImage(file="Arrow_left2.jpg")
b.config(image=image)
b.image = image
b.config(height=70, width=70)
#b.bind("<Button-1>", left_arrow)
#b.bind("<ButtonRelease-1>",stop)
b.grid()
left_button()
main()
Thanks in advance :)