gpt4 book ai didi

python-3.x - gtk3 框架标签位置 3.18 与 3.22

转载 作者:行者123 更新时间:2023-12-04 19:51:01 26 4
gpt4 key购买 nike

我在 Gtk 3.18 和 Gtk 3.22 上运行相同的代码得到不同的视觉结果。下面的代码创建了一个 Gtk.Frame 并将其显示在一个窗口中。 Gtk 框架有红色边框,框架标签文本显示“框架标签文本”。

Here is a screen shot of Gtk 3.18 .框架标签文本显示在红色框架边框上方。

Here is a screen shot of Gtk 3.22 .框架标签文本显示在红色框架边框下方。

我的问题是,如何让 Gtk 3.22 的行为像 Gtk 3.18 一样,并在框架边框上方显示标签?

代码如下:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk # pylint: disable=wrong-import-position

class GtkWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)

def showme(self):
window = Gtk.Window()
gtk_version = "Gtk Version major:{0}, minor:{1}, micro: {2}".format(Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION, Gtk.MICRO_VERSION)
window.set_title(gtk_version)
window.set_default_size(480, 320)
window.connect("delete-event", Gtk.main_quit)
frame = Gtk.Frame.new("Frame Label Text")
frame.set_label_align(0.0, 1.0)
inner_label = Gtk.Label("I am a child label")
frame.add(inner_label)
window.add(frame)

css = b'''
.frame {
border-radius : 10px;
border: 5px solid red;
background-color: gray;
color : white;
}
.label {
border-radius : 5px;
border: 2px solid yellow;
background-color : gray;
color: white;
}
'''
css_provider = Gtk.CssProvider()
css_provider.load_from_data(css)
frame_style_context = frame.get_style_context()
frame_style_context.add_class("frame")
frame_style_context.add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
label_style_context = frame.get_label_widget().get_style_context()
label_style_context.add_class("label")
label_style_context.add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
window.show_all()

if __name__ == "__main__":
win = GtkWindow()
win.showme()
Gtk.main()

最佳答案

GtkCss changed a lot在 3.20 中。

我不是 GtkCss 方面的专家,但它看起来像 3.22 中的 .frame 类指的是整个小部件(参见 Css 节点部分 here)。为了让事情正常进行,您应该调整您的 css 规则并检测确切的 Gtk 版本。

比较以下 css 规则:

3.14(我没有3.18,不过看起来一样)

.frame {
border-radius: 10px;
border: 5px solid red;
background-color: gray;
color: white;
}

.label {
border-radius: 5px;
border: 2px solid yellow;
background-color: gray;
color: white;
}

.frame.border {
border-radius: 5px;
border: 2px solid green;
background-color: cyan;
color: magenta;
}

3.22

.frame {
border-radius: 10px;
border: 5px solid red;
background-color: gray;
color: white;
}

.frame>border {
border-radius: 5px;
border: 2px solid green;
background-color: cyan;
color: magenta;
}

.frame>label {
border-radius: 5px;
border: 2px solid yellow;
background-color: gray;
color: white;
}

他们看起来 this way .另请注意,我已将框架标签垂直对齐设置为 0.5 以使其易于区分

关于python-3.x - gtk3 框架标签位置 3.18 与 3.22,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55111229/

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