gpt4 book ai didi

python - Gtk 3.0 窗口,扩展器内有 TreeView

转载 作者:太空宇宙 更新时间:2023-11-04 05:10:11 27 4
gpt4 key购买 nike

在 python 中,使用 Gtk 3.0,我尝试获取带有笔记本的窗口。在这个笔记本里面,一些扩展器。每个扩展器都包含一个 TreeView 。

经过一些搜索,我有这段代码:

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()

我无法在扩展器中显示 TreeView 。但是没有扩展器,显示 TreeView 。

我在 ubuntun 12.04 上工作并使用 python ihm.py 命令启动我的程序。

有些人可以向我解释为什么它不起作用?

最佳答案

您将笔记本添加到父笔记本两次。删除行

self.Window.add(self.notebook)

这对我有用。奇怪的是您没有收到有关此的错误消息。

关于python - Gtk 3.0 窗口,扩展器内有 TreeView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43184517/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com