Using
Include gtk in your Cargo.toml and set the minimal GTK version required by your project:
[dependencies.gtk]
version = "0.1.1"
features = ["v3_10"]
The APIs aren’t stable yet. Watch the Announcements box above for breaking changes to the crates!
Import the gtk crate and its traits:
extern crate gtk;
use gtk::prelude::*;
Create a window, etc.
use gtk::{Button, Window, WindowType};
fn main() {
if gtk::init().is_err() {
println!("Failed to initialize GTK.");
return;
}
let window = Window::new(WindowType::Toplevel);
window.set_title("First GTK+ Program");
window.set_default_size(350, 70);
let button = Button::new_with_label("Click me!");
window.add(&button);
window.show_all();
window.connect_delete_event(|_, _| {
gtk::main_quit();
Inhibit(false)
});
button.connect_clicked(|_| {
println!("Clicked!");
});
gtk::main();
}
Projects using gtk
If you want yours to be added to this list, please create a Pull Request for it!
