All Posts programming How to create native GUI apps in Rust for Linux ?

How to create native GUI apps in Rust for Linux ?

· 230 words · 2 minute read

Pop! OS developers team is taking this route. They are re-writing all apps and desktop environment (COSMIC DE) in Rust with GTK 4 library binding/wrapper. So, you can create native GUI apps in Rust for Linux with Rust and GTK 4. Take a look at the source code of popsicle app on github. Popsicle is a program is create bootable USB sticks, and they describe it as “Multiple USB File Flasher”. Popsicle app is written in Rust and GTK4 by Pop! OS developers team.

Install Rust 🔗

If you did not install Rust programming language until now, just head to the official website and install it right now using this command I get from the official website.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

GTK 4 🔗

Grab the GTK 4 development library package on your system using cargo.

Bare bone Rust + GTK 4 app 🔗

You can get gtk-rs examples here . Just pick one of those examples and edit it and iterate over it to reach your desired application look and feel.

Here is a little GTK 4 example in Rust 🔗

use gtk::prelude::*;

fn main() {
    let application =
        gtk::Application::new(Some("com.github.gtk-rs.examples.basic"), Default::default());
    application.connect_activate(build_ui);
    application.run();
}

fn build_ui(application: &gtk::Application) {
    let window = gtk::ApplicationWindow::new(application);

    window.set_title(Some("First GTK Program"));
    window.set_default_size(350, 70);

    let button = gtk::Button::with_label("Click me!");

    window.set_child(Some(&button));

    window.show();
}

Use this command to run this little program:

cargo run