我正在学习 Elementary OS 提供的 Vala GTK+3 教程。我明白这段代码:
var button_hello = new Gtk.Button.with_label ("Click me!");
button_hello.clicked.connect (() => {
button_hello.label = "Hello World!";
button_hello.set_sensitive (false);
});
使用 Lambda 函数在单击按钮时更改按钮的标签。我想要做的是调用这个函数:
void clicked_button(Gtk.Button sender) {
sender.label = "Clicked. Yippee!";
sender.set_sensitive(false);
}
我试过这个:
button.clicked.connect(clicked_button(button));
但是当我尝试编译时,我从 Vala 编译中得到了这个错误:
hello-packaging.vala:16.25-16.46: error: invocation of void method not allowed as expression
button.clicked.connect(clicked_button(button));
^^^^^^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
我是 Vala 和 Linux 的新手,所以请保持温和,但有人能指出我正确的方向吗?