Tkコマンド【check(radio)button】 | ..あちゃ! no mic's

..あちゃ! no mic's

クラウドファンディング予定~2026年度
何度でもチャレンジ!
ただいまソーラーピックアップのテスト中

SANTA no Mix


ラジオボタンは複数の選択肢から一つを選択するウィジェット。
チェックボタンはクリックすることにより選択状態と非選択状態を交互に繰り返すウィジェット。
大雑把な説明をするために変数を初期化。
2つのラベルフレームの中にチェックボタンとラジオボタンをそれぞれ仕込んで、パックする。
configureは後で設定を追加したいときに使う。
configureで設定した部分を省くと、GUIで表示された文字のの周りに白い縁が出来るのでそれを取り去るために付けた。
単なるビジュアル上の問題。

ユルい文面で申し訳ないですが・・・。

最後の行のpackのところの-side leftは左から順番に並べてくださいという意味。
-side topで上から並べてください。top、bottom、left、rightがある。
lights camerasとややこしいですが、ただの変数なんで a b cでも構わなかったわけで・・・。


#!/usr/bin/wish

set lights_c 0

set cameras_c 0

set action_c 0

set lights_r 0

set cameras_r 0

set action_r 0

labelframe .lbl1 -text "Steps:" -relief ridge -borderwidth 5 -background dimgray -foreground lightgray

checkbutton .c1 -text "ライト  "  -variable "lights_c"  -bg dimgray -fg lightgray

checkbutton .c2 -text "カメラ  "  -variable "cameras_c" -bg dimgray -fg lightgray

checkbutton .c3 -text "アクション"  -variable "action_c"  -bg dimgray -fg lightgray 

.c1 configure -highlightbackground dimgray -activebackground orange

.c2 configure -highlightbackground dimgray -activebackground orange

.c3 configure -highlightbackground dimgray -activebackground orange

pack .c1 .c2 .c3 -in .lbl1


labelframe .lbl2 -text "Steps:" -relief ridge -borderwidth 5 -background dimgray -foreground lightgray

radiobutton .r1 -text "ライト  "  -variable "lights_r"  -bg dimgray -fg lightgray

radiobutton .r2 -text "カメラ  "  -variable "cameras_r" -bg dimgray -fg lightgray

radiobutton .r3 -text "アクション"  -variable "action_r"  -bg dimgray -fg lightgray

.r1 configure -highlightbackground dimgray -activebackground orange

.r2 configure -highlightbackground dimgray -activebackground orange

.r3 configure -highlightbackground dimgray -activebackground orange

pack .r1 .r2 .r3 -in .lbl2


pack .lbl1 .lbl2 -side left


chmod +x checkbutton.tclで実行可能にしておいて、実行。
ウィンドウが立ち上がる。


チェックボタンのところ。
マウスを重ねるとオレンジに変わる。
-activebackground orangeのところ。



クリックするとマークされる。



もう一度、チェックするとマークが外れる。



次、同様に・・・。



ラジオボタンのところ。
マウスを重ねる。



クリックするとマークが入る。



もう一度、クリックしてもマークが外れない。



次の項目、クリックするとマークが入る。



Tkコマンド【目次】