簡單的 Gtk 視窗與文字
將 Gtk 依賴新增到你的 Cargo.toml
:
[dependencies]
gtk = { git = "https://github.com/gtk-rs/gtk.git" }
使用以下內容建立一個簡單的視窗:
extern crate gtk;
use gtk::prelude::*; // Import all the basic things
use gtk::{Window, WindowType, Label};
fn main() {
if gtk::init().is_err() { //Initialize Gtk before doing anything with it
panic!("Can't init GTK");
}
let window = Window::new(WindowType::Toplevel);
//Destroy window on exit
window.connect_delete_event(|_,_| {gtk::main_quit(); Inhibit(false) });
window.set_title("Stackoverflow. example");
window.set_default_size(350, 70);
let label = Label::new(Some("Some text"));
window.add(&label);
window.show_all();
gtk::main();
}