mdicrist
mdicrist

Reputation: 175

Getting value from spin button Glade/GTK3 (python)

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!

Upvotes: 1

Views: 639

Answers (1)

theGtknerd
theGtknerd

Reputation: 3763

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())

Upvotes: 1

Related Questions