Ryutso
Posts: 4
Joined: Mon May 13, 2019 10:15 pm

Tkinter GUI/alerts for GPIO input pins?

Thu May 23, 2019 6:38 am

I've got about 7 different sensors on a machining press at work that go off when something is wrong, like the safety door being open or there being not enough material left. I'd like to program some sort of GUI that simply has the name of the sensor in a Tkinter Label and circle next to it that turns red or green depending on the state of the sensor. While I have a general grasp on the GPIO input pin programming, wrapping my head around how to program a Tkinter status bar isn't clicking and a lot of the examples I'm seeing do the opposite of what I'd like to do (controlling a physical object with a Tkinter button, rather than having a physical object control a digital interface.)

I've been going over scotty101's code located here: viewtopic.php?f=32&t=41639&sid=969e0399 ... 60#p337497

But still having a bit of trouble wrapping my head around it.

scotty101
Posts: 3562
Joined: Fri Jun 08, 2012 6:03 pm

Re: Tkinter GUI/alerts for GPIO input pins?

Thu May 23, 2019 6:46 am

Can you be a bit more specific about what you are trying to do and what you are finding confusing?

I wrote the code that you shared back when the Pi first came out on to the market so I dare say that there are different way to do things now and there are simpler libraries for reading gpio pins like gpiozero.
That being said, from what you are describing, it should be pretty simple to modify what I wrote to do what you want.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Ryutso
Posts: 4
Joined: Mon May 13, 2019 10:15 pm

Re: Tkinter GUI/alerts for GPIO input pins?

Thu May 23, 2019 6:59 am

scotty101 wrote:
Thu May 23, 2019 6:46 am
Can you be a bit more specific about what you are trying to do and what you are finding confusing?

I wrote the code that you shared back when the Pi first came out on to the market so I dare say that there are different way to do things now and there are simpler libraries for reading gpio pins like gpiozero.
That being said, from what you are describing, it should be pretty simple to modify what I wrote to do what you want.
When a safety sensor is activated on a press, it sends a HIGH signal to a GPIO pin and also stops the press from functioning. So a program similar to yours, but instead of all 30 or so GPIO pins, I only need 7. When one of these pins receives a HIGH signal, the LED should turn from green to red. I think what mainly confuses me is the age of this program like you said, because the pins in your GPIO array don't match up to mine and it's only now I realize that these pins aren't for a RasPi 3B+ and they stop at 2B+.

I don't really need any of the things like the high/low checkbox or the menu to say whether it's passive or input because all the pins I use are going to be input.

I actually was using gpiozero to get the state of the pins.

scotty101
Posts: 3562
Joined: Fri Jun 08, 2012 6:03 pm

Re: Tkinter GUI/alerts for GPIO input pins?

Thu May 23, 2019 7:36 am

Ryutso wrote:
Thu May 23, 2019 6:59 am
now I realize that these pins aren't for a RasPi 3B+ and they stop at 2B+.
The pin layout hasn't changed between the 2B+ and 3B+..

The LED code is simple to use. You just create a new LED and use grid/pack layout to place it on the screen.

Code: Select all

newLED = LED(root,10)
newLED.grid(row=0,column=0)
The text beside it is just a label

Code: Select all

newLEDLabel = Label(root,text="New LED Label")
newLEDLabel.grid(row=0,column=1)
Then you just need to use one of the GPIO libraries to change the LED colour, with RPi.GPIO it could be

Code: Select all

newLED.set(pi.input(7))
You then just need to use the .after method to update the LED periodically.

All the code you need is in the example I produced years ago. Post some code showing your progress and I'm willing to help you debug it.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Return to “Python”