CSS 边距未应用于 Gtk 文本视图
CSS margins not being applied to a Gtk textview
我有以下最小可重现示例代码:
#!/usr/bin/python3
#-*-coding: utf-8-*-
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
win = Gtk.Window()
win.connect("destroy", lambda _: Gtk.main_quit())
box = Gtk.VBox()
win.add(box)
view = Gtk.TextView()
buf = view.get_buffer()
buf.set_text("Hello, this is some text !")
prov = Gtk.CssProvider.new()
prov.load_from_data("""
text {
color: red;
background-color: yellow;
margin: 30px;
}
""".encode())
ctx = win.get_style_context()
ctx.add_provider_for_screen(Gdk.Screen.get_default(), prov, 800)
box.add(view)
win.show_all()
Gtk.main()
字体和背景变色,但不应用边距。为什么,什么可以解决它?
注意:当我使用以下 CSS
将边距应用于框时
text {
color: red;
background-color: yellow;
}
box {
margin: 30px;
}
或添加
`python
view.set("左边距", 10)
view.set("margin_right, 10)
...
the margins are applied. So the cause must be a wrong selector ...
文本视图中没有 css 个边距节点。您需要使用 set_left_margin(left_margin)
set_right_margin(right_margin)
或 set_justification(justification)
.
等函数
用法
Gtk.TextView().set_left_margin(10) /*value is in pixels*/
CSS 个节点
textview.view
├── border.top
├── border.left
├── text
│ ╰── [selection]
├── border.right
├── border.bottom
╰── [window.popup]
css节点只出现在c文档中c documentation
这是 py 文档 py documentation
我有以下最小可重现示例代码:
#!/usr/bin/python3
#-*-coding: utf-8-*-
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
win = Gtk.Window()
win.connect("destroy", lambda _: Gtk.main_quit())
box = Gtk.VBox()
win.add(box)
view = Gtk.TextView()
buf = view.get_buffer()
buf.set_text("Hello, this is some text !")
prov = Gtk.CssProvider.new()
prov.load_from_data("""
text {
color: red;
background-color: yellow;
margin: 30px;
}
""".encode())
ctx = win.get_style_context()
ctx.add_provider_for_screen(Gdk.Screen.get_default(), prov, 800)
box.add(view)
win.show_all()
Gtk.main()
字体和背景变色,但不应用边距。为什么,什么可以解决它?
注意:当我使用以下 CSS
将边距应用于框时text {
color: red;
background-color: yellow;
}
box {
margin: 30px;
}
或添加 `python view.set("左边距", 10) view.set("margin_right, 10) ...
the margins are applied. So the cause must be a wrong selector ...
文本视图中没有 css 个边距节点。您需要使用 set_left_margin(left_margin)
set_right_margin(right_margin)
或 set_justification(justification)
.
用法
Gtk.TextView().set_left_margin(10) /*value is in pixels*/
CSS 个节点
textview.view
├── border.top
├── border.left
├── text
│ ╰── [selection]
├── border.right
├── border.bottom
╰── [window.popup]
css节点只出现在c文档中c documentation
这是 py 文档 py documentation