LoginSignup
0
0

More than 1 year has passed since last update.

tkinterでラジオボタンを使う

Posted at
import tkinter as tk
from tkinter import messagebox

def message():
    messagebox.showinfo('回答', text[var.get()])

root = tk.Tk()
root.geometry('300x250')

text = ['北海道', '群馬', '福井', '和歌山', '島根', '福岡']

for i in range(2):
    root.columnconfigure(i, weight=1)
for i in range(len(text) + 1):
    root.rowconfigure(i, weight=1)    

var = tk.IntVar()
radio = []
for i in range(len(text)):
    radio.append(tk.Radiobutton(root, text=text[i], variable=var, value=i))
    radio[i].grid(row=i, column=0, sticky=tk.W)

answer = tk.Button(root, text='回答', command=message)
answer.grid(row=len(text)+1, column=1, columnspan=2, sticky=tk.EW)

root.mainloop()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0