I’ve never used python before and I’m hoping someone can point me in the right direction with this… I wanted a gui with 2 windows, which I found a code sample for. I’m trying to integrate RPi.GPIO for raspberry pi into this which seems to function fine, what I’ve managed so far is here:
The problem is I can’t access the text widget to add text from my function, from what I understand this is because my functions are outside of the class of the widget I want to alter. So how do I reference a widget from outside of the class and change it?
def check_five():
if (GPIO.input(25) == GPIO.HIGH):
fiveTimes_out()
log.insert('1.0', '5 button down')
root.after(10,check_five)
class MyApp(object):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
self.root = parent
self.root.title("Main frame")
self.frame = Tk.Frame(parent)
self.frame.pack()
....
log = Tk.Text(state='normal', width=70, height=10, wrap='none')
log.place(x=40, y=160)
Should log.insert(‘1.0’, ‘5 button down’) be something like MyApp.log.insert(‘1.0’, ‘5 button down’)?
I could move these functions into the class but then I”m not sure how to get the functions to run with .after or where to place these.
root.after(10,check_five)
root.after(10,check_two)
root.after(10,check_one)
root.after(10,check_toggle)
Any help would be great, thanks.
check_five,check_two,check_oneandcheck_togglemethods of
MyApp.self.log = Tk.TextinMyApp.__init__. That way, othermethods in
MyAppcan referenceself.log.if __name__ == "__main__":part of the script, useapp.check_fiveinstead ofcheck_fiveto referenceapp‘scheck_fivemethod. And similarly for the othercheck_*methods.