42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import tkinter as tk
|
|
from tkinter import messagebox
|
|
|
|
def on_click():
|
|
name = entry.get()
|
|
checked = var_chk.get()
|
|
msg = f"こんにちは {name} さん!\nチェック状態: {checked}"
|
|
messagebox.showinfo("挨拶", msg)
|
|
|
|
root = tk.Tk()
|
|
root.title("Tkinter GUI サンプル")
|
|
root.geometry("400x300") # 幅×高さ
|
|
|
|
# ラベル
|
|
label = tk.Label(root, text="名前を入力してください:", font=("Arial", 12))
|
|
label.pack(pady=5)
|
|
|
|
# 入力欄
|
|
entry = tk.Entry(root, width=30)
|
|
entry.pack(pady=5)
|
|
|
|
# チェックボックス
|
|
var_chk = tk.BooleanVar()
|
|
chk = tk.Checkbutton(root, text="同意します", variable=var_chk)
|
|
chk.pack(pady=5)
|
|
|
|
# リストボックス
|
|
listbox = tk.Listbox(root, height=4)
|
|
for item in ["りんご", "バナナ", "みかん", "ぶどう"]:
|
|
listbox.insert(tk.END, item)
|
|
listbox.pack(pady=5)
|
|
|
|
# ボタン
|
|
btn = tk.Button(root, text="実行", command=on_click)
|
|
btn.pack(pady=10)
|
|
|
|
# 終了ボタン
|
|
btn_quit = tk.Button(root, text="終了", command=root.quit)
|
|
btn_quit.pack(pady=5)
|
|
|
|
root.mainloop()
|