Reputation: 584
In python, with Gtk 3.0, I try to obtain a windows with a notebook. Inside this notebook, some expander. Each expander would contain a treeview.
After some search, I have this code :
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Hello World")
# Create liststore which will be contained within treeview
# liststore has 3 rows and 3 columns
self.store = Gtk.ListStore(str, str, float)
self.store.append(["string1.1", "string1.2", 1.0])
self.store.append(["string2.1", "string2.2", 2.0])
self.store.append(["string3.1", "string3.2", 3.0])
# Create treeview which will be contained within one expander
# treeview has 3 columns and contain liststore
self.tree = Gtk.TreeView(self.store)
for i, column_title in enumerate(["col1", "col2", "col3"]):
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(column_title, renderer, text=i)
self.tree.append_column(column)
# Addind a callback to selection_changed event of treeview
select = self.tree.get_selection()
select.connect("changed", self.on_tree_selection_changed)
# Create expander which will be contained within one notebook page
# Adding treeview inside expander
self.page1 = Gtk.Expander()
self.page1.set_border_width(10)
self.page1.add(self.tree)
# Create notebook and adding expander inside first page
self.notebook = Gtk.Notebook()
self.add(self.notebook)
self.notebook.append_page(self.page1, Gtk.Label('Page1'))
self.Window = Gtk.Window()
self.Window.add(self.notebook)
self.show_all()
def on_tree_selection_changed(self, selection):
model, treeiter = selection.get_selected()
if treeiter != None:
print("You selected", model[treeiter][0])
win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
I don't manage to display treeview inside expander. But without expander, treeview is displayed.
I work on ubuntun 12.04 and launch my programm with python ihm.py
command.
Some people can explain me why it don't work?
Upvotes: 2
Views: 324
Reputation: 3745
You are adding the notebook to a parent two times. Remove the line
self.Window.add(self.notebook)
This worked for me. It is strange that you don't get an error message about this.
Upvotes: 1