【发布时间】:2021-09-26 06:58:37
【问题描述】:
我正在使用此代码将当前时间写入应用中的 Gtk.Label。
public bool update_time () {
var now = new GLib.DateTime.now_local ();
var settings = new GLib.Settings ("org.gnome.desktop.interface");
var time_format = Granite.DateTime.get_default_time_format (settings.get_enum ("clock-format") == 1, false);
time1_label = new Gtk.Label (now.format (time_format)) {
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER,
margin_top = 5
};
time1_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
time1_label.tooltip_text = time_format;
time1_label.xalign = 0;
return true;
}
时间显示正确,但我希望标签在更改时更新为最新时间。我该怎么做?
也许以某种方式使用Timeout,但我不知道如何。
【问题讨论】: