我嘗試製作一個基於Gtk.Grid的HTML表格(在單元格和表格周圍有邊框)。由於表格只包含標籤,我開始嘗試對標籤進行樣式設置。我嘗試這樣做:如何在Gtk.Grid的單元格周圍放置邊框,就像在HTML表格中一樣?
label {
border: 1px solid black;
}
,但它沒有工作,雖然在同一個CSS文件,我能夠在窗口背景色設置爲lightblue
。
所以我簡化了我的問題到以下兩個文件。
test.py:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.add(Gtk.Label("These words should be red."))
provider = Gtk.CssProvider()
provider.load_from_path("style.css")
win.get_style_context().add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
#win.add(Gtk.Label("These words should pe red.")) # the same behavior: the label's text is not painted red
win.show_all()
Gtk.main()
的style.css:
window {
background-color: lightblue; /* this works */ }
label {
color: red; /* this does not work */ }
在MSYS2 MinGW的32位I嘗試都這樣:
[email protected] MINGW32 ~/python+gtk/test
$ winpty python2 test.py
和這
[email protected] MINGW32 ~/python+gtk/test
$ python2 test.py
但我不知道如何設計標籤的樣式,因爲上面的代碼無法正常工作,正如我在評論中指定的那樣。終端上沒有打印錯誤或警告。
我有這個版本的GTK + &的Python 2.7的安裝:
[email protected] MINGW32 ~/python+gtk/test
$ pacman -Q mingw-w64-i686-gtk3
mingw-w64-i686-gtk3 3.22.16-1
[email protected] MINGW32 ~/python+gtk/test
$ python2 --version
Python 2.7.13
我用的是最新的Windows 10創造者升級爲2017年8月,5日,安裝了所有更新。我使用MSYS2對終端中的pacman -Syyu
指令進行的所有升級和更新。
這裏有一些相關的鏈接(3個鏈接到官方文件和1個鏈接到另一個SO問題):
- https://lazka.github.io/pgi-docs/#Gtk-3.0/classes/Label.html#Gtk.Label
- https://developer.gnome.org/gtk3/stable/GtkLabel.html#GtkLabel.description
- https://developer.gnome.org/gtk3/stable/theming.html
- 這是問題,它教會了我可以在GTK +應用程序中加載CSS文件的指令:CSS styling in GTKSharp
在這些情況下,我如何設計標籤?或者,至少請引導我通過其他方式在Gtk.Grid的單元格周圍製作邊框。
看一看https://stackoverflow.com/questions/32162372/which-gtk-elements-support-which-css-properties 並非所有的小部件都支持所有的CSS屬性。 –