-
-
Save mrichardson23/5434591 to your computer and use it in GitHub Desktop.
# Tkinter and GPIO together | |
from Tkinter import * | |
import RPi.GPIO as GPIO | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(24, GPIO.OUT) | |
GPIO.output(24, GPIO.LOW) | |
def toggle(): | |
if GPIO.input(24): | |
GPIO.output(24, GPIO.LOW) | |
toggleButton["text"] = "Turn LED On" | |
else: | |
GPIO.output(24, GPIO.HIGH) | |
toggleButton["text"] = "Turn LED Off" | |
root = Tk() | |
root.title("Toggler") | |
toggleButton = Button(root, text="Turn LED On", command=toggle) | |
toggleButton.pack(side=LEFT) | |
quitButton = Button(root, text="Quit", command=exit) | |
quitButton.pack(side=LEFT) | |
root.mainloop() |
pi@raspberrypi:~ $ sudo python tk.py
File "tk.py", line 13
else:
......^
IndentationError: unindent does not match any outer indentation level
there are some spaces on line 11 :
if GPIO.input(24):
delete those and press tab once and it should work as intended.
Hi. This is perfect for what I'm trying to do. I need a real small button the screen like this to trigger a ham radio tuner.
However, instead of toggling the pin, what I'm trying to do is to press the GUI button, causing the GPIO pin to go high for one second, then return to a low state. (having the displayed text change would be nice, but not really needed)
I've tried everything I can think of, without success. (I don't know how to program in Python obviously).
I don't know if "toggle" is a necessary part of this script, but tried removing the if/else and use a sleep statement, but it's way over my head.
Any suggestions?
After a lot of reading on the syntax, I think I have it running the way I want.
cant get this to work, i'm using Python 3 idle. any ideas?