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

  • Home
  • SEARCH
  • 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 3323520
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:18:45+00:00 2026-05-17T23:18:45+00:00

For a small timer app I want to write a GTK interface where I

  • 0

For a small timer app I want to write a GTK interface where I can set the desired time. Here is a picture of the interface:

alt text

However, I am having trouble reading out the fields of the spin buttons. My envisaged procedure for this is the following:

  1. Read out the buttons using methods for each button

Here is one of the methods that does this:

# Get the fields of the spinbuttons
def get_seconds(self, widget, spin):
    self.rSeconds = spin.get_value_as_int()

It is then called like this:

    button = gtk.Button("Start")
    button.connect("clicked", self.get_seconds, spinnerS)
  1. Create a timer object with the data from the buttons

This is planned to be accomplished using this method:

    # Create the timer object ...
   def prepare_timer(self, widget, hours, minutes, seconds, title, text):
     self.timer = eggTimer(hours, minutes, seconds, title, text)

Which is called here:

button.connect("clicked", self.prepare_timer, self.rHours, self.rMinutes, self.rSeconds, "some title", "some text")

Unfortunately, when running the script I get the following error message:

Traceback (most recent call last):
File "GTKInterface.py", line 140, in <module>
SpinButtonExample()
File "GTKInterface.py", line 126, in __init__
button.connect("clicked", self.prepare_timer, self.rHours, self.rMinutes, self.rSeconds, "Title", "Text")
AttributeError: SpinButtonExample instance has no attribute 'rSeconds'

To check whether there really is no instance of that variable, I programmed a short method to print it:

   def returnS(self, widget):
       print self.rSeconds

And surprisingly this method can “see” self.rSeconds. This makes me wonder what determines the visibility of the variable. What am I doing wrong to read this out?

  • 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-05-17T23:18:45+00:00Added an answer on May 17, 2026 at 11:18 pm

    You try to pass the attribute self.rHours to the connect method, but at that point the attribute doesn’t exist yet (the clicked handlers haven’t executed yet).

    Note that even if you fill in self.rHours before calling connect, it will pass the value at the time of connecting, not at the time of the handler executing.

    You can solve this by passing self.rHours etc directly to eggTimer in prepare_timer.

    But it would be even easier to just combine all the click handlers into one, and use local variables instead of self.rHours etc. There’s no reason to split your code over many click handlers like this.

    Edit: BTW, you can also use nested functions instead of methods:

    ...
    def prepare_timer(widget):
        self.timer = eggTimer(
            spinnerH.get_value_as_int(),
            spinnerM.get_value_as_int(),
            spinnerS.get_value_as_int(),
            "Title", "Text")
    button.connect("clicked", prepare_timer)
    ...
    

    Keep it simple!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a small app which can be used in order to
I want to write an app to transpose the key a wav file plays
I've been tasked to write a small app to be used by a single
Every time I try to run a small application that uses a Derby DB
my company is small with only one full time tester, and mostly we're doing
In my free time I started writing a small multiplayer game with a database
I've been tinkering with small functions on my own time, trying to find ways
We should forget about small efficiencies, say about 97% of the time: premature optimization
I have been asked to write an app which screen scrapes info from an
I am putting together a small app that has a leaderboard concept in it.

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.