如何使用 Gtk 在对话框中向用户询问某些内容?

Bar*_*ith 3 gtk message dialog vala

我最近开始使用 Vala 编程语言开发 Gtk+ 3.x。我曾经使用 C# 和 Visual Studio 来完成几乎相同的任务,但后来转向了 Linux。

如何在对话框中询问简单的“确定”/“取消”问题?在 C# 中,使用 MessageBox.Show() 非常简单。然而,Gtk 似乎复杂得令人烦恼,而且我所做的每次 Google 搜索都会给我带来有关对话框和事件处理程序的技术性胡言乱语。

有没有一个简单的功能,所以我可以做类似的事情:

bool result = MessageBox.AskQuestion("Do you want to save?");
Run Code Online (Sandbox Code Playgroud)

谢谢,

巴里·史密斯

Bar*_*ith 5

其实是经过反复尝试才发现的……

public bool show_question(string message, Gtk.Window window, MessageType mt)
{
    Gtk.MessageDialog m = new Gtk.MessageDialog(window, DialogFlags.MODAL, mt, ButtonsType.OK_CANCEL, message);
    Gtk.ResponseType result = (ResponseType)m.run ();
    m.close ();
    if (result == Gtk.ResponseType.OK)
    {
        return true;
    }
    else
    {
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)