Bitte warten...

GTK+ 3: Listen-Widgets

Gtk.TreeView

► GTK+ 3 Dokumentation: Gtk.TreeView Gtk.TreeViewColumn Gtk.CellRendererText Gtk.ListStore

Das Widget Gtk.TreeView kann dazu verwendet werden, Datensätze tabellenartig darzustellen. Dazu werden in dem Gtk.TreeView die einzelnen Spalten mit Gtk.TreeViewColumn festgelegt und mit append_column() dem Gtk.TreeView hinzugefügt.

Um die einzelnen Zellen der Tabelle mit Textinhalten füllen zu können, müssen diese mit Gtk.CellRendererText konfiguriert werden.

Die konkreten Inhalte der Tabellenzeilen werden mit append() in ein Gtk.ListStore geschrieben (s. Zeile 73).

Code kopieren
  1. self.liststore01 = Gtk.ListStore(int, str, str, str, str, str, str, str)
  2. self.treeview01 = Gtk.TreeView(self.liststore01)
  3. self.treeview01.set_rules_hint(True) # Zeilenfarbe wechselnd
  4. self.box03.pack_start(self.treeview01, True, True, 0)
  5. self.treeviewcolumn01 = Gtk.TreeViewColumn("ID")
  6. self.cellrenderertext01 = Gtk.CellRendererText()
  7. self.treeviewcolumn01.pack_start(self.cellrenderertext01, True)
  8. self.treeviewcolumn01.add_attribute(self.cellrenderertext01, 'text', 0)
  9. self.treeviewcolumn01.set_resizable(True)
  10. self.treeview01.append_column(self.treeviewcolumn01)
  11. self.treeviewcolumn02 = Gtk.TreeViewColumn("Vorname")
  12. self.cellrenderertext02 = Gtk.CellRendererText()
  13. self.treeviewcolumn02.pack_start(self.cellrenderertext02, True)
  14. self.treeviewcolumn02.add_attribute(self.cellrenderertext02, 'text', 1)
  15. self.treeviewcolumn02.set_resizable(True)
  16. self.treeview01.append_column(self.treeviewcolumn02)
  17. self.treeviewcolumn03 = Gtk.TreeViewColumn("Nachname")
  18. self.cellrenderertext03 = Gtk.CellRendererText()
  19. self.treeviewcolumn03.pack_start(self.cellrenderertext03, True)
  20. self.treeviewcolumn03.add_attribute(self.cellrenderertext03, 'text', 2)
  21. self.treeviewcolumn03.set_resizable(True)
  22. self.treeview01.append_column(self.treeviewcolumn03)
  23. self.treeviewcolumn04 = Gtk.TreeViewColumn("Geburtsdatum")
  24. self.cellrenderertext04 = Gtk.CellRendererText()
  25. self.treeviewcolumn04.pack_start(self.cellrenderertext04, True)
  26. self.treeviewcolumn04.add_attribute(self.cellrenderertext04, 'text', 3)
  27. self.treeviewcolumn04.set_resizable(True)
  28. self.treeview01.append_column(self.treeviewcolumn04)
  29. self.treeviewcolumn05 = Gtk.TreeViewColumn("PLZ")
  30. self.cellrenderertext05 = Gtk.CellRendererText()
  31. self.treeviewcolumn05.pack_start(self.cellrenderertext05, True)
  32. self.treeviewcolumn05.add_attribute(self.cellrenderertext05, 'text', 4)
  33. self.treeviewcolumn05.set_resizable(True)
  34. self.treeview01.append_column(self.treeviewcolumn05)
  35. self.treeviewcolumn06 = Gtk.TreeViewColumn("Ort")
  36. self.cellrenderertext06 = Gtk.CellRendererText()
  37. self.treeviewcolumn06.pack_start(self.cellrenderertext06, True)
  38. self.treeviewcolumn06.add_attribute(self.cellrenderertext06, 'text', 5)
  39. self.treeviewcolumn06.set_resizable(True)
  40. self.treeview01.append_column(self.treeviewcolumn06)
  41. self.treeviewcolumn07 = Gtk.TreeViewColumn("Straße")
  42. self.cellrenderertext07 = Gtk.CellRendererText()
  43. self.treeviewcolumn07.pack_start(self.cellrenderertext07, True)
  44. self.treeviewcolumn07.add_attribute(self.cellrenderertext07, 'text', 6)
  45. self.treeviewcolumn07.set_resizable(True)
  46. self.treeview01.append_column(self.treeviewcolumn07)
  47. self.treeviewcolumn08 = Gtk.TreeViewColumn("Hausnummer")
  48. self.cellrenderertext08 = Gtk.CellRendererText()
  49. self.treeviewcolumn08.pack_start(self.cellrenderertext08, True)
  50. self.treeviewcolumn08.add_attribute(self.cellrenderertext08, 'text', 7)
  51. self.treeviewcolumn08.set_resizable(True)
  52. self.treeview01.append_column(self.treeviewcolumn08)
  53. personen = []
  54. personen.append(['Hans', 'Meier', '21.04.1987', '10001', 'Musterstadt', 'Hafenstraße', '34'])
  55. personen.append(['Monika', 'Müller', '03.11.1956', '10002', 'Musterdorf', 'Am Acker', '3'])
  56. personen.append(['Paul', 'Schmidt', '17.09.1972', '10001', 'Musterstadt', 'Bahnhofstraße', '129'])
  57. personen.append(['Paula', 'Lehmann', '11.06.1999', '10002', 'Musterdorf', 'Dorfstraße', '17'])
  58. self.liststore01.clear()
  59. self.PersonsRowIter = []
  60. count = 0
  61. for person in personen:
  62. count += 1
  63. self.PersonsRowIter += [self.liststore01.append([count, person[0], person[1], person[2], person[3], person[4], person[5], person[6]])]