Files
h2inc-old/Gui test/gtk_test.py
2018-02-20 21:00:31 +01:00

49 lines
1.3 KiB
Python

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import time
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title = 'Hello World')
self.val = 0
self.box = Gtk.Box(spacing=6)
self.add(self.box)
self.button1 = Gtk.Button(label = 'Hello')
self.button1.connect('clicked', self.on_button1_clicked)
self.box.pack_start(self.button1, True, True, 0)
self.button2 = Gtk.Button(label = 'Goodbye')
self.button2.connect('clicked', self.on_button2_clicked)
self.box.pack_start(self.button2, True, True, 0)
self.pbar = Gtk.ProgressBar()
self.pbar.set_fraction(0.0)
self.box.pack_start(self.pbar, True, True, 0)
def on_button1_clicked(self, widget):
print('Hello')
while self.val < 1:
self.update_pbar(self.pbar)
print('Goodbye')
Gtk.main_quit()
def on_button2_clicked(self, widget):
print('Goodbye')
def update_pbar(self, widget):
self.val += 0.1
self.pbar.set_fraction(self.val)
time.sleep(0.5)
while Gtk.events_pending():
Gtk.main_iteration()
win = MyWindow()
win.connect('delete-event', Gtk.main_quit)
win.show_all()
Gtk.main()