Dec-13-2020, 07:18 PM
Hello,
I'm just started learning Python. Program will work under RPi.
General functionality is: when gpio input is grounded picture red picture should me displayed, when input is on open circuit to ground white picture should be displayed.
I tried to use while loop with extra function def. - only my program stuck.
I'm not sure that way with Tkinker is good one.
Can you help me with any direction when I should go?
I'm just started learning Python. Program will work under RPi.
General functionality is: when gpio input is grounded picture red picture should me displayed, when input is on open circuit to ground white picture should be displayed.
from Tkinter import * from PIL import Image from PIL import ImageTk import os import sys import RPi.GPIO as GPIO root = Tk() #root.geometry("800x600") #root.attributes('-type', 'dock') #root.focus_force() GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) IP = 21 GPIO.setup(IP, GPIO.IN, pull_up_down=GPIO.PUD_UP) root.geometry("800x600") #root.attributes('-type', 'dock') root.focus_force() if os.environ.get('DISPLAY','') == '': print('no display found. Using :0.0') os.environ.__setitem__('DISPLAY', ':0.0') GPIO.setmode(GPIO.BCM) global p1_rd global p1_wh p1_rd = ImageTk.PhotoImage(Image.open("1_rd.png")) p1_wh = ImageTk.PhotoImage(Image.open("1_wh.png")) im_1 = Label(image= p1_wh, borderwidth=0) im_1.grid(row=0, column=0) global trig1 trig1 = 1 def ChangeImage1(self): global trig1 if GPIO.input(21) == 0: if GPIO.input(21) != trig1: im_1 = Label(image= p1_rd, borderwidth=0) im_1.grid(row=0, column=0) trig1 = 0 else: if trig1 != 1: im_1 = Label(image= p1_wh, borderwidth=0) im_1.grid(row=0, column=0) trig1 = 1 ChangeImage1(None) #root = Tkinter.Tk() #state_det1(None) root.mainloop() GPIO.cleanup()Program gives expected result only if gpio is triggered when program is starting up (once)
I tried to use while loop with extra function def. - only my program stuck.
I'm not sure that way with Tkinker is good one.
Can you help me with any direction when I should go?