Вот MCVE для справки:
#!/usr/bin/env python
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib
import os, sys
class GUI (Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title = "events_pending example")
box = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
self.add(box)
sw = Gtk.ScrolledWindow()
box.pack_start(sw, True, True, 0)
p_bar = Gtk.ProgressBar()
box.pack_start(p_bar, False, False, 0)
model = Gtk.ListStore(int)
view = Gtk.TreeView(model = model)
sw.add(view)
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn("Numbers", renderer, text=0)
view.append_column(column)
self.show_all()
self.set_size_request(300, 300)
self.connect("destroy", self.on_window_destroy)
GLib.timeout_add(1000, self.add_numbers, model, p_bar)
def add_numbers (self, treemodel, p_bar):
for i in range(10000):
treemodel.append([i])
if i != 0: #do not divide by zero
i = float(i) # convert variable to float first!
p_bar.set_fraction(i/9999)
while Gtk.events_pending():
Gtk.main_iteration()
def on_window_destroy(self, window):
Gtk.main_quit()
def main():
app = GUI()
Gtk.main()
if __name__ == "__main__":
sys.exit(main())