Good evening: I speak from Colombia, the problem is that I am doing a project in which I must have an object counter that passes a sensor. Well, I hope I can explain myself: code1 works perfectly, what a button connected to GPIO 24 does is simple and every time you press it it prints 1 in 1 in an ascending way, but this is done from the console. the question is how can I get this value printed by the interface or Gui from tkinter on a label,
Try to do it with code 2 but it does not work
codigo 1
import RPi.GPIO as GPIO #libreria to control the pins
import time #libreria for the use of time (sleep)
GPIO.setmode (GPIO.BCM)
GPIO.setup (24, GPIO.IN)
GPIO.setwarnings (False)
cont = 0
while True:
inputValue = GPIO.input (24)
if (inputValue == False):
cont = cont + 1
print ("pressed button" + str (cont))
time.sleep (.5)
time.sleep (.01)
codigo 2
import RPi.GPIO as GPIO #libreria para controlar los pines
import time #libreria para el uso de tiempo (sleep)
from tkinter import*
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
GPIO.setwarnings(False)
raiz=Tk()
contador = StringVar()
contador.set("0"+" U/s")
label1=Label(raiz, background="#00dbde", textvariable=contador, font=("Helvetica", 40,"bold"))
label1.place(x=20, y=10)
raiz.attributes("-fullscreen", True)
raiz.bind("<1>",exit)
def exit():
raiz.quit()
def leeboton():
cont=0
while True:
inputValue = GPIO.input(23)
if(inputValue == True):
raiz.after(2000, leeboton)
cont=cont+1
contador.set(str(int(cont))+" U/s")
time.sleep(.5)
raiz.after(2000, leeboton)
raiz.mainloop()
only the GUI comes out printing this variable " contador.set ("0" + "U / s") "but does nothing else when pressing the button