Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8986139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:28:49+00:00 2026-06-15T21:28:49+00:00

I’ve never used python before and I’m hoping someone can point me in the

  • 0

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:

http://pastebin.com/9aWDgg0r

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:28:50+00:00Added an answer on June 15, 2026 at 9:28 pm
    • Make check_five, check_two, check_one and check_toggle
      methods of MyApp.
    • Define self.log = Tk.Text in MyApp.__init__. That way, other
      methods in MyApp can reference self.log.
    • In the if __name__ == "__main__": part of the script, use
      app.check_five instead of check_five to reference app‘s
      check_five method. And similarly for the other check_* methods.

    import Tkinter as Tk
    import time
    import RPi.GPIO as GPIO
    
    GPIO.setmode(GPIO.BCM)
    
    # setup 5 output pin
    GPIO.setup(11, GPIO.OUT)
    # setup 2 output pin
    GPIO.setup(14, GPIO.OUT)
    # setup 1 output pin
    GPIO.setup(15, GPIO.OUT)
    
    # set low output states on start
    GPIO.output(11, GPIO.LOW)
    GPIO.output(14, GPIO.LOW)
    GPIO.output(15, GPIO.LOW)
    
    # setup 5 input pin
    GPIO.setup(25, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
    # setup 2 input pin
    GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
    # setup 1 input pin
    GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
    
    # setup window toggle pin
    GPIO.setup(22, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
    
    
    # out functions light certain led a number of times     
    def fiveTimes_out():
        #1
        GPIO.output(11, GPIO.HIGH)
        time.sleep(0.200)
        GPIO.output(11, GPIO.LOW)
        time.sleep(0.200)
        #2
        GPIO.output(11, GPIO.HIGH)
        time.sleep(0.200)
        GPIO.output(11, GPIO.LOW)
        time.sleep(0.200)
        #3
        GPIO.output(11, GPIO.HIGH)
        time.sleep(0.200)
        GPIO.output(11, GPIO.LOW)
        time.sleep(0.200)
        #4
        GPIO.output(11, GPIO.HIGH)
        time.sleep(0.200)
        GPIO.output(11, GPIO.LOW)
        time.sleep(0.200)
        #5          
        GPIO.output(11, GPIO.HIGH)
        time.sleep(0.200)
        GPIO.output(11, GPIO.LOW)
        time.sleep(0.200)
    
    def twoTimes_out():
        #1
        GPIO.output(14, GPIO.HIGH)
        time.sleep(0.200)
        GPIO.output(14, GPIO.LOW)
        time.sleep(0.200)
        #2
        GPIO.output(14, GPIO.HIGH)
        time.sleep(0.200)
        GPIO.output(14, GPIO.LOW)
        time.sleep(0.200)        
    
    def oneTimes_out():
        #1
        GPIO.output(15, GPIO.HIGH)
        time.sleep(0.200)
        GPIO.output(15, GPIO.LOW)
        time.sleep(0.200)
    
    
    
    ########################################################################
    class OtherFrame(Tk.Toplevel):
        """"""
    
        #----------------------------------------------------------------------
        def __init__(self):
            """Constructor"""
            Tk.Toplevel.__init__(self)
            self.geometry("640x480+0+0")
            self.configure(background = 'yellow')
    
            self.title("otherFrame")
    
    ########################################################################
    class MyApp(object):
        """"""
    
        #----------------------------------------------------------------------
        def __init__(self, parent):
    
            """Constructor"""
            self.root = parent
            self.root.title("Main frame")
            self.frame = Tk.Frame(parent)
            self.frame.pack()
    
            btn = Tk.Button(self.frame, text = "Other Window", command = self.openFrame)
            btn.pack()
    
            btn2 = Tk.Button(self.frame, text = "Function test", command = twoTimes_out)
            btn2.pack()
    
            titleLabel = Tk.Label(text = "My Label")
            titleLabel.place(x = 40, y = 60)
    
            insertLabel = Tk.Label(text = "Label")
            insertLabel.place(x = 170, y = 110)
    
            self.log = Tk.Text(state = 'normal', width = 70, height = 10, wrap = 'none')
            self.log.place(x = 40, y = 160)
    
            thanksLabel = Tk.Label(text = "Thank You!")
            thanksLabel.place(x = 70, y = 350)
    
            self.log.insert('1.0', 'here is my text to insert')
    
    
        #----------------------------------------------------------------------
        def hide(self):
            """"""
            self.root.withdraw()
    
        #----------------------------------------------------------------------
        def openFrame(self):
            """"""
            self.hide()
            subFrame = OtherFrame()
            handler = lambda: self.onCloseOtherFrame(subFrame)
            btn = Tk.Button(subFrame, text = "Close", command = handler)
            btn.pack()
            secondPageLabel = Tk.Label(text = "HI")
            secondPageLabel.place(x = 170, y = 110)
    
        #----------------------------------------------------------------------
        def onCloseOtherFrame(self, otherFrame):
            """"""
            otherFrame.destroy()
            self.show()
    
        #----------------------------------------------------------------------
        def show(self):
            """"""
            self.root.update()
            self.root.deiconify()
    
        # in functions check if buttons are pushed and run specific functions
        # also write messages to log    
    
        def check_five(self): 
            if (GPIO.input(25) == GPIO.HIGH):
                fiveTimes_out()
                self.log.insert('1.0', '5 button down')
            else:
                self.log.insert('1.0', '5 button up')
            root.after(10, self.check_five)
    
        def check_two(self): 
            if (GPIO.input(24) == GPIO.HIGH):
                twoTimes_out()
                self.log.insert('1.0', '2 button down')
            else:
                self.log.insert('1.0', '2 button up')
            root.after(10, self.check_five)
    
        def check_one(self): 
            if (GPIO.input(23) == GPIO.HIGH):
                oneTimes_out()
                self.log.insert('1.0', '1 button down')
            else:
                self.log.insert('1.0', '1 button up')
            root.after(10, self.check_five)
    
        # check if window toggle button is pushed
        # you reference self in check_toggle, so check_toggle should probably be a method.
        def check_toggle(self): 
            if (GPIO.input(22) == GPIO.HIGH):
                self.openFrame()                 
            root.after(10, check_toggle)
    
    #----------------------------------------------------------------------
    if __name__ == "__main__":
        root = Tk.Tk()
    
        root.geometry("640x480+0+0")
        root.configure(background = 'red')
        app = MyApp(root)
        root.after(10, app.check_five)
        root.after(10, app.check_two)
        root.after(10, app.check_one)
        root.after(10, app.check_toggle)
        root.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.