So I have just picked up python as of three days ago and I am in the process of making a program. This is also my first experience with programming so bare with me. I have spent an UNHEALTHY amount of time trying to learn and so far I have been able to crawl my way forward but I am afraid I'm stuck.
I am in the process of making a GUI to control a GPIO function I created that just makes a couple lights blink. For the time being it just makes two LED's blink simultaneously with a user inputted delay and a user inputted number of loops using tkinter's Entry widget. This is where my problem arises, when I try to pull the inputs from the Entry widget's I get a 'str' error, which makes sense because I assume the entry is of the string data type and my blink function must be looking for an integer data type? However, if I force this to be an integer I then get an "invalid for literal int() base 10" error prompt. Please help.
Here is my current script:
Disclaimer: There may be some syntax errors. The firewall at Deere doesn't allow me to connect to the network so I had to type all of this again.
I am in the process of making a GUI to control a GPIO function I created that just makes a couple lights blink. For the time being it just makes two LED's blink simultaneously with a user inputted delay and a user inputted number of loops using tkinter's Entry widget. This is where my problem arises, when I try to pull the inputs from the Entry widget's I get a 'str' error, which makes sense because I assume the entry is of the string data type and my blink function must be looking for an integer data type? However, if I force this to be an integer I then get an "invalid for literal int() base 10" error prompt. Please help.
Here is my current script:
Disclaimer: There may be some syntax errors. The firewall at Deere doesn't allow me to connect to the network so I had to type all of this again.
import tkinter as tk
root=tk.Tk()
root.title("LED Controller")
import sys
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(11,GPIO.OUT)
CycleLabel = tk.Label(root, text="Cycles", font="Verdana 12 bold")
CycleLabel.grid(row=1,column=1)
CycleInput = tk.Entry(root)
CycleInput.grid(row=1,column=2)
CycleInput.focus_set()
cycle=CycleInput.get()
SpeedLabel = tk.Label(root, text="Speed", font="Verdana 12 bold")
SpeedLabel.grid(row=1,column=1)
SpeedInput = tk.Entry(root)
SpeedInput.grid(row=2,column=2)
SpeedInput.focus_set()
speed = SpeedInput.get()
def callback():
print (CycleInput.get())
print (SpeedInput.get())
def Blink(cycle,speed):
for platypus in range (0, cycle): ** This is the line that the error always points to.
print("Loop" + str(platypus+1))
GPIO.output(7,True)
GPIO.output(11, True)
time.sleep(speed)
GPIO.output(7, False)
GPIO.output(11, False)
time.sleep(speed)
print("Done")
ButtonFrame = tk.Frame(root)
ButtonFrame.grid(row=3,column=1,columnspan=3)
B2 = tk.Button(ButtonFrame, text="Start", width=10, command=lambda:Blink(cycle,speed), font="Verdana 10 bold")
B2.grid(row=3,column=2)
B1 = tk.Button(ButtonFrame, text"Print Inputs", width=10, command=callback, font="Verdana 10 bold")
B1.grid(row=3,column=1)
def clear():
CycleInput.delete(0, 'end')
SpeedInput.delete(0, 'end')
B3 = tk.Button(ButtonFrame, text="Clear", width=10, command=clear, font="Verdana 10 bold")
B3.grid(row=3,column=3)
CloseFrame = tk.Frame(root)
CloseFrame.grid(row=4, column=1, columnsapn=3)
B4 = tk.Button(CloseFrame, text="Close", width=20, command=root.destroy, font="Verdana 10 bold", activebackground='red')
B4.grid(row=4,column=2)
