PythonのTkiterを用いて,GUIを作っています.
Tkiterは,あまり有名ではないのか,あまり参考サイトがなく困っています.
CheckBox(TkinterではCheckButton?)を,プログラムから動的にチェックを切り替えたいのですが,その方法がわかりません.
更に,CheckBoxの連動について.
例えば以下のソースだと,正常に動作します.
lang
1from Tkinter import * 2 3root = Tk() 4 5opts1 = BooleanVar() 6opts1.set(True) 7opts2 = BooleanVar() 8opts2.set(False) 9opts3 = BooleanVar() 10opts3.set(True) 11 12Label(text ='Check Button').pack() 13Checkbutton(text = 'option 1', variable = opts1).pack() 14Checkbutton(text = 'option 2', variable = opts2).pack() 15Checkbutton(text = 'option 3', variable = opts3).pack() 16 17root.mainloop() 18
しかし,以下のように書くと,想定外の動作が起こります.
全てのCheckBoxが連動してしまうのです.
例えば,3番目のCheckBoxをクリックすると,全てのCheckBoxが連動してチェックされたり消えたりします.
これはなぜなのでしょうか?
lang
1import Tkinter 2 3root = Tkinter.Tk() 4 5array = ["a","s","d","f","g","h","f","k","l"] 6 7for d in range(len(array)): 8 b = Tkinter.Checkbutton(root, text = d, variable = True) 9 b.place(x=1,y=20*d) 10root.mainloop() 11
よろしくお願いいたします.
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/02/16 17:16
2015/02/17 09:21
2015/02/17 18:39