import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk # Create a TreeView with three columns tree_view = Gtk.TreeView() tree_view.append_column(Gtk.TreeViewColumn("Name", Gtk.CellRendererText(), text=0)) tree_view.append_column(Gtk.TreeViewColumn("Age", Gtk.CellRendererText(), text=1)) tree_view.append_column(Gtk.TreeViewColumn("Gender", Gtk.CellRendererText(), text=2)) # Add data to the TreeView store = Gtk.ListStore(str, int, str) store.append(["John", 25, "Male"]) store.append(["Jane", 30, "Female"]) store.append(["Bob", 40, "Male"]) tree_view.set_model(store) # Display the TreeView window = Gtk.Window() window.add(tree_view) window.show_all() Gtk.main()
import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk # Create a ListBox list_box = Gtk.ListBox() # Add items to the ListBox for i in range(1, 6): item = Gtk.ListBoxRow() label = Gtk.Label(f"Item {i}", xalign=0) item.add(label) list_box.add(item) # Display the ListBox window = Gtk.Window() window.add(list_box) window.show_all() Gtk.main()In this example, we use Gtk.CellRendererText indirectly to display text in a ListBox. We create a ListBox and add Gtk.ListBoxRow items to it, which contain a label with the text "Item i". We set xalign to 0 to left-align the text. Finally, we display the ListBox in a window. Overall, Gtk.CellRendererText is a useful class for displaying text in various Gtk widgets, and it is part of the Gtk package library.