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()
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme