本文介绍了Mac风格加入按钮(分段控制)与Gtk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果两个按钮看起来像是一个带有通过它的线的矩形,这是如何完成的?

解决方案

在GTK 3.0及更高版本中,使用 INLINE_TOOLBAR style class或 LINKED style class。

 #! / usr / bin / env python 

from gi.repository import Gtk

button_names = [
Gtk.STOCK_ABOUT,
Gtk.STOCK_ADD,
Gtk.STOCK_REMOVE,
Gtk.STOCK_QUIT]
buttons = [Gtk.ToolButton.new_from_stock(name)for button_names]

toolbar = Gtk.Toolbar()$
toolbar.insert(button,-1)
style_context = toolbar.get_style_context()
style_context.add_class(Gtk.STYLE_CLASS_INLINE_TOOLBAR)

window = Gtk.Window()
window.set_size_request(200,50)
window.add(工具栏)
window.connect('delete-event',Gtk.m ain_quit)
window.show_all()

Gtk.main()


I've seen it done in the ubuntu software center, and with a few gnome apps.

Where two buttons look like a single rectangle with a line through it, how is this being done?

解决方案

In GTK 3.0 and later, use the INLINE_TOOLBAR style class or LINKED style class.

#!/usr/bin/env python

from gi.repository import Gtk

button_names = [
    Gtk.STOCK_ABOUT,
    Gtk.STOCK_ADD,
    Gtk.STOCK_REMOVE,
    Gtk.STOCK_QUIT]
buttons = [Gtk.ToolButton.new_from_stock(name) for name in button_names]

toolbar = Gtk.Toolbar()
for button in buttons:
    toolbar.insert(button, -1)
style_context = toolbar.get_style_context()
style_context.add_class(Gtk.STYLE_CLASS_INLINE_TOOLBAR)

window = Gtk.Window()
window.set_size_request(200, 50)
window.add(toolbar)
window.connect('delete-event', Gtk.main_quit)
window.show_all()

Gtk.main()

这篇关于Mac风格加入按钮(分段控制)与Gtk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:01