Project Setup
Let's begin by installing all necessary tools. First, follow the instructions on the GTK website in order to install GTK 4. Then install Rust with rustup.
Now, create a new project by executing:
cargo new my-gtk-app
Add the following line to your dependencies in Cargo.toml
, where X.X
should be replaced with the most up-to-date version of the gtk4 crate.
gtk = { version = "X.X", package = "gtk4" }
To use functionality that has been added to later releases, you have to specify this as a feature. Per default
gtk4-rs
is compatible with all GTK 4 releases. For example, if you want to use functionality that was introduced with GTK 4.6, you would add the following to yourgtk
dependency inCargo.toml
.gtk = { version = "X.X", package = "gtk4", features = ["v4_6"]}
This will only work if your available GTK version is indeed >= 4.6. You can get the version by executing the following command:
pkg-config --modversion gtk4
Now, you can run your application by executing:
cargo run