[pygtk] NEWBIE QUESTION: Simple spinbutton example?
Darren Enns
darethehair at gmail.com
Sun Mar 23 07:54:10 WST 2008
Hello all!
I am slowly learning the Python language, and now I am moving into
developing GUI apps using PyGTK. I am bumbling/stumbling around with
'spinbutton'. I know how to make the spinbutton appear, but I don't
know how to *properly* return the final value for a spinbutton back to
my mainline code. Can someone provide a very simple example of:
1) A mainline creating a window and a button
2) When pushed, the button should call a module which opens another
(temporary) window to display a 'spinbutton'
3) The final value of the spinbutton when the 2nd window is closed
should return (somehow) the value back to the calling mainline
Here is the minimum that I am currently using to accomplish this (please
don't laugh!):
#!/usr/bin/env python2.5
import gtk
def get_value(widget,spin,value):
value = "%d" % spin.get_value_as_int()
print "value=",value
return
def get_spin(widget):
window = gtk.Window()
adjustment = gtk.Adjustment(0, -90, 90, 1, 1, 1)
spinbutton = gtk.SpinButton(adjustment,0,0)
value = 0
spinbutton.connect("changed",get_value,spinbutton,value)
print "the final value is: ",value
spinbutton.show()
window.add(spinbutton)
window.show()
return
def main():
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("destroy", gtk.main_quit)
window.show_all()
table = gtk.Table(2,1,False)
button = gtk.Button("Get Spin Value")
button.connect("clicked",get_spin)
table.attach(button,0,1,0,1)
table.show()
button.show()
window.add(table)
window.show_all()
gtk.main()
return
if __name__ == '__main__': main()
Dare
More information about the pygtk
mailing list