import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk # create a list store with two columns: "name" and "progress" store = Gtk.ListStore(str, float) store.append(["Download 1", 0.5]) store.append(["Download 2", 0.8]) # create a tree view and set the list store as its model tree = Gtk.TreeView(store) # create a progress bar cell renderer and add it to the tree view renderer = Gtk.CellRendererProgress() column = Gtk.TreeViewColumn("Progress", renderer, value=1) tree.append_column(column) # add a text cell renderer for the "name" column renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn("Name", renderer, text=0) tree.append_column(column) # show the tree view window = Gtk.Window() window.add(tree) window.show_all() Gtk.main()
import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, GObject class MyWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="CellRendererProgress Example") # create a list store with two columns: "name" and "progress" self.store = Gtk.ListStore(str, float) self.store.append(["Download 1", 0.5]) self.store.append(["Download 2", 0.8]) # create a tree view and set the list store as its model self.tree = Gtk.TreeView(self.store) # create a progress bar cell renderer and add it to the tree view self.renderer = Gtk.CellRendererProgress() column = Gtk.TreeViewColumn("Progress", self.renderer, value=1) self.tree.append_column(column) # add a text cell renderer for the "name" column self.renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn("Name", self.renderer, text=0) self.tree.append_column(column) # add a button to update the progress value button = Gtk.Button(label="Update Progress") button.connect("clicked", self.update_progress) self.add(button) self.add(self.tree) def update_progress(self, widget): # update the progress value for the first item in the list store self.store[0][1] += 0.1 # refresh the cell renderer to show the new progress value self.renderer.set_property("value", self.store[0][1]) self.tree.queue_draw() window = MyWindow() window.connect("destroy", Gtk.main_quit) window.show_all() Gtk.main()This example creates a MyWindow class that extends the Gtk.Window class and contains a tree view with a progress bar column and a button to update the progress value. When the button is clicked, the progress value for the first item in the list store is increased by 0.1 and the cell renderer is refreshed to show the new value. Package library: gi.repository Gtk, GObject In conclusion, the CellRendererProgress is a useful component of the Gtk library for creating progress bars in table cells. It can be used in a variety of Python applications, such as file downloaders, database managers, and more. The package library for these examples is gi.repository Gtk, with an additional use of the GObject library in the second example.