Skip to content

Instantly share code, notes, and snippets.

@kujirahand
Created July 16, 2024 10:31
Show Gist options
  • Save kujirahand/e36b9f4f94cc6d3a3361ef97b46e93b4 to your computer and use it in GitHub Desktop.
Save kujirahand/e36b9f4f94cc6d3a3361ef97b46e93b4 to your computer and use it in GitHub Desktop.
Rustとtkで一番簡単なGUIプログラミング(hello_tk/src/main.rs)
use tk::*;
use tk::cmd::*;
fn main() -> TkResult<()> {
// Tkの初期化 --- (*1)
let tk = make_tk!()?;
let root = tk.root();
// ウィンドウ上にフレームを作成 --- (*2)
let content = root
.add_ttk_frame(())?
.pack(())?;
content.configure( -padding(12) )?; // 余白を設定
// ラベルを配置 --- (*3)
content
.add_label("lbl1" -text("Tkのテスト"))?
.pack(())?;
// ボタンを配置 --- (*4)
content
.add_button("btn1" -text("閉じる") -command("destroy ."))?
.pack( -side("bottom") )?;
// メインループ --- (*5)
Ok( main_loop() )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment