2

I am trying out gtk-rs and while there is certainly documentation available, it is much too hard to understand for a beginner. I just see many different impls and traits and generics, but there never are any code examples from which I can learn. Usually I look at code, use it, and then go through it line by line so I can understand it. But this isn't possible here.

Can somebody please help me?

I used to program in PyGTK and I found an old sample code:

def report_error(self, reason):
    dialog = Gtk.MessageDialog(Gtk.Window(), 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "You did something wrong")
    dialog.format_secondary_text(reason)
    dialog.run()
    dialog.destroy()

But how, just how can I do this in Rust/gtk-rs? I am completely lost.

casualcoder
  • 231
  • 2
  • 11
  • Sorry to say, but this is offtopic, as you want us to either find a tutorial for you or act as a code-writing-service. Stackoverflow is neither of both. You may ask on the [rust forum](https://users.rust-lang.org/) or try some of the online tutorials from gtk-rs. Please take yourself the time to [learn rust](https://doc.rust-lang.org/stable/book/second-edition/index.html) as well as it seems, that you don't have much experience with it. Building a GUI is too hard for your first experiments. – hellow Nov 08 '18 at 07:08
  • I apologize. :-( – casualcoder Nov 08 '18 at 12:56

1 Answers1

2

There is an example demonstrating a message box:

extern crate gtk;
use gtk::prelude::*;
use gtk::{ButtonsType, DialogFlags, MessageType, MessageDialog, Window};

fn main() {
    if gtk::init().is_err() {
        println!("Failed to initialize GTK.");
        return;
    }
    MessageDialog::new(None::<&Window>,
                       DialogFlags::empty(),
                       MessageType::Info,
                       ButtonsType::Ok,
                       "Hello World").run();
}
Theodoros Chatzigiannakis
  • 28,773
  • 8
  • 68
  • 104
VP.
  • 15,509
  • 17
  • 91
  • 161
  • I looked everywhere, but not the start page of the crate. I did some more research on what each lines does and customized it to my needs. Thank you so much for your help! – casualcoder Nov 08 '18 at 12:57
  • You should always start from the `Documentation` link on the crate page on `crates.io`. – VP. Nov 08 '18 at 13:22