Python and Tkinter Widget pseudo LED creation - Raspberry Pi Forums


i'm new have managed create tkinter/python program can use buttons , check buttons control gpio output lines such turning them on/off in groups , individually.
know little classes , modules/function basics of both python , tkinter.(having worked through excellent tutorials 'learn python hard way' (zed shaw) , thinking in tkinter.(stephen ferg))
having few problems around getting screen widget display status of gpio input line.
have tried use canvas widget create circular pseudo led can use fill property colour it's centre either red or green depending on status of input.
seems sort of work...once when first run program.
if run program switch in 2 positions appears filled either red or green depending on switch position when first run program not update.
think may event binding.
have noticed tkinter buttons , check buttons can use command binding event binding , have used successfully.(and variable checkbutton)
know how bind led fill gpio status.
have tried wrapping while true loop around if ,else statement not display anything.
scotty101 has great program standards advanced user , looking @ code staring abyss me , understand little of it.
have modified code i/o lines , works fine want know how myself scratch.

here code:
# tkinter , gpio
# class structure.

tkinter import *
import rpi.gpio gpio
import time

class myapp:

def __init__ (self, parent):

self.myparent = parent
self.myframe = frame(parent)

# set mode , pin 23 input
gpio.setmode(gpio.bcm)
gpio.setup(23, gpio.in)

# set frame geometry padding.
self.myframe.pack(
padx="2m",
pady="1m",
ipadx="2m",
ipady="1m"
)

# invoke pseudo led , control colour based on gpio pin 23
if gpio.input(23)== true:
colour = "green"
else:
colour = "red"


self.canvas1 = canvas(self.myframe, height=25, width=25)
self.canvas1.create_oval(5,5,20,20, fill=colour)
self.canvas1.pack()


# main loop tk link , class stuff.
root = tk()
root.title("led/switch")
myapp = myapp(root)
root.mainloop()

ideas?
know how code window thingy seen on these forums.

hi spong23,

key tkinter gui program use of tkinter .after method periodically reads state of gpio , sets led appropriately.
i'll have @ code , propose simplest way make work.


raspberrypi



Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial