
tkinterでButtonを作成する上の設定の記事となります。
※更新中の記事になります※
|
1 2 |
x = button(フレーム等 ,オプション) x.pack() |
Button オプション一覧
| オプション名 | 見た目 | 説明 | 値 |
| text textvariable | ![]() | ボタンの文字 | “好きな文字列”・数値 |
| command | なし | 押したときの処理 | 関数名 |
| fg(foreground) activeforeground | ![]() fg = “red” | 文字色 | “色名” or”#色コード” |
| bg(background) activebackground | ![]() bg = “red” | 背景色 | “色名”or”#色コード” |
| font | ![]() font=(“MS明朝M”,20,”bold”) | フォント 大きさ 等 | (“フォント名”, フォントサイズ, その他) |
| width height | ![]() width=10,height=2 | 幅、高さ | 文字数 |
| padx pady | ![]() padx=10,pady=10 | padding | px |
| state | ![]() | 状態 | “normal” “disabled” |
| relief overrelief | ![]() | 見た目 | “flat”等 |
| anchor justify | ![]() | 文字の位置 文字の揃え | “n” “s” “w” “e” “center”等 |
| repeatdelay repeatinterval | なし | 長押し機能 | ミリ秒 |
| image | ![]() | 画像の配置 | tk.photoImage |
| compound | ![]() | 画像と文字の関係 | “top” “center” |
| cursor | ![]() | カーソルの形 | “watch”等 |
| bitmap | ![]() | bitmap表示 | “error”等 |
| disabledforeground | ![]() | stateが”disabled” の時の文字色 | “色名”or”色コード” |
| highlightcolor highlightbackground highlightthickness | Buttonだと効果なし? | 効果なし? | 効果なし? |
| takefocus | ![]() | タブでフォーカス するかどうか | True False |
| underline | ![]() | 一文字だけの アンダーライン | 数値 |
| wraplength | ![]() | 文字の折り返し幅 | px |
| default | stateと同じのため省略 | 省略 | 省略 |
buttonの配置方法
ウィジェットの配置方法(pack・grid・place)については3つの方法があります。
pack
|
1 2 |
x = button(root, text = "Zack") x.pack() |
grid
|
1 2 |
x = button(root, text = "Zack") x.grid(column = 0, row = 0) |
place
|
1 2 |
x = button(root, text = "Zack") x.place(x = 0, y = 0) |


















