mercoledì 22 agosto 2012

Esempio GUI con PYGtk

Al contrario degli esempio precedenti PyGtk non funziona con la versione 3.x di Python per cui e' necessario usare un compilatore della serie 2.x



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

class SecondWin:
        def __init__(self):
            self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
            self.win.connect("delete_event", self.delete_event)
            self.win.connect("destroy", self.destroy)
            #self.win.set_resizable(gtk.FALSE)
            self.win.set_title('Progress Bar')
            self.win.set_border_width(5)
            self.win.resize(200,100)

            self.vbox = gtk.VBox()
            self.win.add(self.vbox)

            adjustment = gtk.Adjustment(0, 0, 100, 5, 10, 0)
            self.hscale = gtk.HScale(adjustment)
            self.vbox.pack_start(self.hscale)
            self.hscale.set_digits(0)
            self.hscale.connect("value-changed", self.scale_moved)

            self.label = gtk.Label(str="   ")
            self.vbox.pack_start(self.label)

            self.progressbar = gtk.ProgressBar()
            self.vbox.pack_start(self.progressbar)
           
            self.win.show_all()

        def scale_moved(self, event):
            self.label.set_text(str(self.hscale.get_value()))
            self.progressbar.set_fraction(self.hscale.get_value()/100)
           
        def delete_event(self, widget, event, data=None):
            return gtk.FALSE
        def destroy(self, widget, data=None):
            return gtk.main_quit()
        def main(self):
            gtk.main()

if __name__ == "__main__":
    second = SecondWin()
    second.main()

----------------------------------------------