Oct-27-2020, 03:04 PM
(This post was last modified: Oct-27-2020, 06:35 PM by ramazanemreosmanoglu.)
Hello;
I writed this codes for creating book table:
Console outputs:
I writed this codes for creating book table:
import os import gi def get_all_books(): """ Structure: ( [isbn, name, author, page_number], [isbn, name, author, page_number], [isbn, name, author, page_number], ... ) """ return ( ["039103948", "Name", "John Doe", "923"], ["039103948", "Name", "John Doe", "923"], ["039103948", "Name", "John Doe", "923"], ["039103948", "Name", "John Doe", "923"], ) UI_FILE = os.path.join(os.getcwd(), "window.ui") gi.require_version("Gtk", "3.0") from gi.repository import Gtk class SignalHandler: def selection_changed(self, selection): ... def create_treeview(): store = Gtk.ListStore(int, str, str, int) books = get_all_books() map(lambda b: store.append(b), books) # Add books to store tree = Gtk.TreeView(store) isbn_col = Gtk.TreeViewColumn("ISBN") name_col = Gtk.TreeViewColumn("Name") author_col = Gtk.TreeViewColumn("Author") page_n_col = Gtk.TreeViewColumn("P. Number") isbn_r, name_r, author_r, page_n_r = Gtk.CellRendererText(), Gtk.CellRendererText(), Gtk.CellRendererText(), Gtk.CellRendererText() l = [ (isbn_col, isbn_r), (name_col, name_r), (author_col, author_r), (page_n_col, page_n_r), ] for i in l: i[0].pack_start(i[1], True) i[0].add_attribute(i[1], "text", l.index(i)) map( lambda i: tree.append_column(i[0]), l, ) select = tree.get_selection() select.connect("changed", SignalHandler().selection_changed) return tree builder = Gtk.Builder() builder.add_from_file(UI_FILE) builder.connect_signals(SignalHandler()) if __name__ == "__main__": window = builder.get_object("main_window") box = builder.get_object("all_books_box") box.pack_end(create_treeview(), True, True, 0) window.show_all() Gtk.main()When i run this codes, opening a blank window.
Console outputs:
~/LibraryManagement ยป python3 src/main.py emre@emre-mint src/main.py:71: PyGTKDeprecationWarning: Using positional arguments with the GObject constructor has been deprecated. Please specify keyword(s) for "model" or use a class specific constructor. See: https://wiki.gnome.org/PyGObject/InitializerDeprecations tree = Gtk.TreeView(store)Why it doesn't working?