morris555's diary

高校生のブログです。

python de Gtk+3 #9

プログレスバーいってみようww

#!/usr/bin/env python
# -*- coding:utf-8 -*-

from gi.repository import Gtk, GObject


class MainWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title=u'ProgressBar')

        self.Progressbar = Gtk.ProgressBar()
        self.add(self.Progressbar)   
        
        self.timeout_id = GObject.timeout_add(50, self.on_timeout, None)
        self.activity_mode = False
        
        self.connect('delete-event', Gtk.main_quit)
        self.show_all()

    def on_timeout(self, user_data):
        if self.activity_mode:
            self.Progressbar.pulse() 
        else:
            new_value = self.Progressbar.get_fraction() + 0.01
            if new_value > 1:
                Gtk.main_quit()
            self.Progressbar.set_fraction(new_value)
        return True

if __name__ == '__main__':
    MainWindow()
    Gtk.main()

5秒で終了します。

その他

今回はちょっと難しかった(泣)
間違ってたら教えてください。

あとコメントもどんどんお願いしますww

最近ページビューが増えてきていてとても嬉しいmorris555でした。