如何使用gtk3在python中创建类似列表的gui?
我试图在我的InputPage对象中创建类似于列表的用户界面gui(没有Glade),可以在整个gnome3用户界面中看到: 我所拥有的只是这个(请注意,我只想添加按钮+和-与它们在第一张图像中显示的样式相同,我想保持列表中的列不变): 由于某些原因,按钮比预期的宽,并且工具栏没有填充水平空间。 这是我的密码:如何使用gtk3在python中创建类似列表的gui?,python,user-interface,gtk,gtk3,Python,User Interface,Gtk,Gtk3,我试图在我的InputPage对象中创建类似于列表的用户界面gui(没有Glade),可以在整个gnome3用户界面中看到: 我所拥有的只是这个(请注意,我只想添加按钮+和-与它们在第一张图像中显示的样式相同,我想保持列表中的列不变): 由于某些原因,按钮比预期的宽,并且工具栏没有填充水平空间。 这是我的密码: class InputPage(Gtk.Box): def __init__(self): Gtk.Box.__init__(self) self.grid = G
class InputPage(Gtk.Box):
def __init__(self):
Gtk.Box.__init__(self)
self.grid = Gtk.Grid()
self.grid.set_column_homogeneous(True)
self.grid.set_row_homogeneous(True)
self.add(self.grid)
#Creating the ListStore model
self.software_liststore = Gtk.ListStore(str, str, int)
for software_ref in software_list:
self.software_liststore.append(list(software_ref))
#creating the treeview, making it use the filter as a model, and adding the columns
self.treeview = Gtk.TreeView()
for i, column_title in enumerate(["Name", "Frequency", "Amplitude"]):
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(column_title, renderer, text=i)
self.treeview.append_column(column)
#button.connect("clicked", self.on_selection_button_clicked)
#setting up the layout, putting the treeview in a scrollwindow, and the buttons in a row
self.scrollable_treelist = Gtk.ScrolledWindow()
self.scrollable_treelist.set_vexpand(True)
self.grid.attach(self.scrollable_treelist, 0, 0, 10, 7)
#Toolbar
list_add = Gtk.Button()
list_add.add(Gtk.Image(icon_name='list-add-symbolic', visible=True))
list_insert_object = Gtk.Button()
list_insert_object.add(Gtk.Image(icon_name='insert-object-symbolic', visible=True))
list_remove = Gtk.Button()
list_remove.add(Gtk.Image(icon_name='list-remove-symbolic', visible=True))
self.toolbar = Gtk.ButtonBox(spacing=5)
self.toolbar.get_style_context().add_class('inline-toolbar')
self.toolbar.add(list_add)
self.toolbar.add(list_remove)
self.toolbar.add(list_insert_object)
self.toolbar.set_hexpand(True)
self.grid.attach(self.toolbar, 0,7,4,1)
#self.grid.attach_next_to(self.toolbar, self.scrollable_treelist, Gtk.PositionType.BOTTOM, 1, 1)
# for i, button in enumerate(self.buttons[1:]):
#self.grid.attach_next_to(button, self.buttons[i], Gtk.PositionType.RIGHT, 1, 1)
self.scrollable_treelist.add(self.treeview)
self.show_all()
您在第一个屏幕截图的底部看到的是一个标准的GtkToolbar,带有
内联工具栏
样式类
GtkToolbar不一定需要位于窗口顶部。你可以把它们放在任何地方,就像普通的小部件一样。所有小部件都有一个定义小部件外观的样式上下文;每个样式上下文都应用了一个或多个类。这些类是CSS类;设置小部件的样式就像在HTML中说class=“classname”
以下是一种可能的方法:
get\u style\u context()
方法add_class()
方法,传递字符串“内联工具栏”
。(我相信这有一个符号常量;我不知道Python中是什么。)“linked”
类添加到工具栏
祝你好运