create gtk4 window in rust

To create a GTK4 window in Rust, you'll need to use the gtk crate, which provides Rust bindings for the GTK4 library. Here's some example code to create a simple window:

main.rs
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow};

fn main() {
    let app = Application::builder()
        .application_id("com.example.myapp")
        .build();

    app.connect_activate(|app| {
        // Create a new window
        let window = ApplicationWindow::new(app);

        // Set the title of the window
        window.set_title("My Window");

        // Set the default size of the window
        window.set_default_size(350, 70);

        // Show the window
        window.show_all();
    });

    app.run();
}
541 chars
25 lines

This code initializes a new GTK4 application, creates a window, sets the window's title and default size, and then shows the window. Note that connect_activate is an application signal that is emitted when the application has been started; the code for creating and showing the window is executed when this signal is emitted.

gistlibby LogSnag