我有以下可重复的最小示例代码:
#!/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;
}
或添加`pythonview.set("margin left",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文档中
这是py文档py文档