Parth1234
Posts: 72
Joined: Mon Mar 12, 2018 3:14 pm

GPIO Pin Configuration

Sun Jan 13, 2019 9:40 am

I want to configure GPIO Pin of Pi in GUI. I have found this way to do it

Code: Select all

import tkinter

#creates box
window =tkinter.Tk()

window.geometry("%dx%d+%d+%d" % (330, 80, 200, 150))
window.title("Raspberry Pi")

#data
data={
    'GPIO12':"LED Pin",
    'GPIO16':"Buzzer Pin",
    'GPIO14':"Switch Pin",
    }

#updates text
def boxtext(new_value):
    display.config(text = data[new_value])

#create a dropdown list
var = tkinter.StringVar()
var.set('PIN Configuration')
p = tkinter.OptionMenu(window, var, *data, command=boxtext)
p.pack()

display = tkinter.Label(window)
display.pack()

window.mainloop()
I have doubt I think this is not way to set GPIO pin in the program, any advice

ptimlin
Posts: 10
Joined: Tue Jan 08, 2019 7:44 pm

Re: GPIO Pin Configuration

Mon Jan 14, 2019 6:11 pm

Hi,

I am brand new to Raspnberry Pis as well as Python, but I am trying to learn and part of that is reading some of these posts to see what I can learn from them. Anyway...

Don't you need to first import your GPIO library?

Code: Select all

import RPi.GPIO as GPIO
More info can be found here...
https://sourceforge.net/p/raspberry-gpi ... asicUsage/

Update: I guess that is if you use that library. There is also the GPIOZERO library. I believe both are built into the standard Raspbian OS. More info on that one found here...
https://gpiozero.readthedocs.io/en/stable/recipes.html

Return to “Python”