1

I am new to python and I am currently trying to get a value from a spin button that has been created in Glade. I have the following code to try to get the value from the button then use it to filter data:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class Handler:

    def on_spinbutton1_value_changed(self, SpinButton):
        Area = self.builder.get_object("spinbutton1")
        Area = self.Area.get_value_as_int()
        print Area

builder = Gtk.Builder()
builder.add_from_file("DataApp.glade")
builder.connect_signals(Handler())

window = builder.get_object("MainWindow")
window.show_all()

Gtk.main()

I get no errors however the number entered also does not print. Any suggestions on how to get this running? Any help is greatly appreciated!

1 Answer 1

1

I am guessing your program format is wrong. Try this:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GdkPixbuf, Gdk
import os, sys

UI_FILE = "DataApp.glade"    

class GUI:
    def __init__(self):    
        self.builder = Gtk.Builder()
        self.builder.add_from_file(UI_FILE)
        self.builder.connect_signals(self)    
        window = self.builder.get_object('MainWindow')    
        window.show_all()

    def on_spinbutton1_value_changed(self, spinbutton):
        print spinbutton.get_value_as_int()

def main():
    app = GUI()
    Gtk.main()

if __name__ == "__main__":
    sys.exit(main())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.