On Thu, 2006-06-22 at 22:30 -0700, Christopher Spears wrote:
I am trying to create a gui that consists of a
vertical scrollbar and two buttons.  I want to be able
to pick a number representing degrees Fahrenheit using
the scrollbar.  When I click the Convert button after
picking a number, the gui would convert the number
into degrees Celsius and print the answer to the
screen.  Here is what I have written so far:

#!/usr/bin/python

import pygtk
pygtk.require('2.0')
import gtk

def scale_set_default_values(scale):
        scale.set_update_policy(gtk.UPDATE_CONTINUOUS)
        scale.set_digits(1)
        scale.set_value_pos(gtk.POS_LEFT)
        scale.set_draw_value(True)
        scale.set_sensitive(True)
        
class Conversion_GUI:
        
        def convert_to_celsius(self, adj):
                #print "Data: ", adj.value
                self.degC = (adj.value - 32)/1.8
                return
                
        
        def print_celsius(self, widget):
                #degC = self.convert_to_celsius(adj1)
                print self.degC #data
                
                
        def __init__(self):
                self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
                self.window.connect("destroy", lambda w:
gtk.main_quit())
                self.window.set_title("Convert to Celsius")
                self.window.set_default_size(200,240)
                
                box1 = gtk.VBox(False, 0)
                self.window.add(box1)
                
                box2 = gtk.HBox(False, 10)
                box2.set_border_width(10)
                box1.pack_end(box2, True, True, 0)
                
                box3 = gtk.HBox(False, 10)
                box3.set_border_width(10)
                box1.pack_end(box3, True, True, 0)
                
                adj1 = gtk.Adjustment(32.0, 32.0, 213.0, 0.1, 1.0,
1.0)
                self.vscale = gtk.VScale(adj1)
                self.vscale.set_size_request(20, 300)
                scale_set_default_values(self.vscale)
                box1.pack_start(self.vscale, True, True, 0)
                
        
        
adj1.connect("value_changed",self.convert_to_celsius)
                
                quit_button = gtk.Button("Quit")
                quit_button.connect("clicked", lambda
w:gtk.main_quit())
                self.degC = 0
                convert_button = gtk.Button("Convert")
                convert_button.connect("clicked",
self.print_celsius)
                box3.pack_start(convert_button, True, True, 0)
                box2.pack_start(quit_button, True, True, 0)
                
                self.vscale.show()
                convert_button.show()
                quit_button.show()
                box3.show()
                box2.show()
                box1.show()
                self.window.show()
                
        def main(self):
                gtk.main()
                return 0
        
if __name__ == '__main__':
        convert = Conversion_GUI()
        convert.main()

> Basically, the scrollbar feeds information into
> convert_to_celsius, which does the conversion.  What I
> want to do is somehow store the information generated
> in convert_to_celsius in a variable and send it to
> print_celsius to print out the answer after the
> Convert button is pressed.
> 
> I've looked at the tutorials and the docs and couldn't
> find anything, so I thought someone on this mailing
> list could give me advice.

That should work (not tested).  Basically you just can use a class
global variable to store the converted variable in.  "self.degC"  I also
removed a few function parameters you'll see.

I think you should change the adj1.connect() to store the adj value and
print the degF value in something in your window, then use the commented
out method in the print_celcius to convert then print the temp.

That should give you a few more ideas :)
-- 
Brian <[EMAIL PROTECTED]>

_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to