gtk hello3 button

This commit is contained in:
2023-07-05 11:28:28 +02:00
parent 695a1defaf
commit 8671a962b4
2 changed files with 45 additions and 0 deletions

9
gtk4/hello3/Cargo.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "hello2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gtk = { version = "0.6.6", package = "gtk4", features = ["v4_8"] }

36
gtk4/hello3/src/main.rs Normal file
View File

@@ -0,0 +1,36 @@
use gtk::prelude::*;
use gtk::{glib, Application, ApplicationWindow, Button};
const APP_ID: &str = "com.clonbg.Helloword2";
fn build_ui(app: &Application) {
// Create a button with label and margins
let button = Button::builder()
.label("Press me!")
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.build();
// Connect to "clicked" signal of `button`
button.connect_clicked(|button| {
// Set the label to "Hello World!" after the button has been clicked on
button.set_label("Hello World!");
});
let window = ApplicationWindow::builder()
.application(app)
.title("Mi aplicacióng gtk")
.child(&button)
.build();
// presenta la ventana, será la última orden
window.present();
}
fn main() -> glib::ExitCode {
let app = Application::builder().application_id(APP_ID).build();
app.connect_activate(build_ui);
app.run()
}