前提
Pythonの基礎文法がある程度理解できている
Tkinterについての知識がある(なければこちらをどうぞ)
プログラム
#!/usr/bin/env python
# -*- coding: utf8 -*-
import sys
from Tkinter import *
import tkMessageBox
root = Tk()
root.title(u"Software Title")
root.geometry("400x300")
# 状態の変更
def change_state():
# チェックされているラジオボタンを取得
checked = v.get()
if ( checked == 1 ):
# radio1がチェックされていたら
radio2.configure( state = "disabled" )
radio3.configure( state = "disabled" )
elif ( checked == 2 ):
# radio2がチェックされていたら
radio1.configure( state = "disabled" )
radio3.configure( state = "disabled" )
elif ( checked == 3 ):
# radio3がチェックされていたら
radio1.configure( state = "disabled" )
radio2.configure( state = "disabled" )
else:
print "error"
# ラジオボタンのグループ
v = IntVar()
v.set(0)
# ラジオボタン
radio1 = Radiobutton(text = u"項目1", variable = v, value = 1, command = change_state)
radio1.pack()
radio2 = Radiobutton(text = u"項目2", variable = v, value = 2, command = change_state)
radio2.pack()
radio3 = Radiobutton(text = u"項目3", variable = v, value = 3, command = change_state)
radio3.pack()
root.mainloop()