【发布时间】:2018-03-24 21:47:03
【问题描述】:
我正在尝试在 GTK 中为我的标签添加 CSS 样式,但我不知道如何设置文件。我目前在开头添加了一个包含,但我收到此错误:
我也不知道我是否正确地实现了这一点,对 GTK 编程来说非常新。有人可以帮我正确设置 CSS 实现吗?
#include<gtk/gtk.h>
public class MyApp : Gtk.Application {
public MyApp() {
Object (
application_id: "com.github.omerntosi.gtkHangman",
flags: ApplicationFlags.FLAGS_NONE
);
}
protected override void activate() {
var main_window = new Gtk.ApplicationWindow(this);
main_window.set_default_size(1000,800);
main_window.title = "GTK Hangman";
var grid = new Gtk.Grid();
grid.orientation = Gtk.Orientation.VERTICAL;
grid.row_spacing = 6;
var topHalf = new Gtk.Grid();
topHalf.orientation = Gtk.Orientation.HORIZONTAL;
grid.row_spacing = 6;
var man = new Gtk.Image();
man.set_from_file("../src/img/placeholder-500x350.png");
topHalf.add(man);
GtkCssProvider cssProvider = gtk_css_provider_new();
gtk_css_provider_load_from_path(cssProvider, "style.css", NULL);
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(cssProvider), GTK_STYLE_PROVIDER_PRIORITY_USER);
var sol = new Gtk.Label("____ ______");
sol.set_use_markup(true);
topHalf.add(sol);
grid.add(topHalf);
main_window.add(grid);
main_window.show_all();
}
public static int main(string[] args) {
var app = new MyApp();
return app.run(args);
}
}
【问题讨论】:
-
哪种编程语言? Python? JavaScript? C++(使用 GtkMM?)?这不是原生 GTK(用 C 编码)!
-
我的错,这是在瓦拉
-
请注意,根据 AFAIK,Vala 已经过时了。
-
是的,我明白这一点,但它仍然是推荐用于 Elementary OS 开发的主要语言,所以我想我会尝试一下。不过,我意识到要在上面实际找到文档是多么困难。
-
包含行不是有效的 Vala 代码,它是 C。摆脱它。