1
我有一個單選按鈕讓我選擇0,1或2.下面的腳本在終端打印0,1或2,但我希望它做'東西'取決於我選擇的是什麼。Python - Tkinter RadioButton如果聲明
例如,如果我選擇0,我想它做一個root.destroy() 如果我選擇1,我想它做別的事情等
我想我需要聲明一個全局變量,但似乎並不奏效。
這是腳本。
root = Tk()
v = IntVar()
v.set(0) # set to 0 pics as default. Just looks prettier...
languages = [
("0 Pics",0),
("1 Pic",1),
("2 Pics",2),
]
def ShowChoice():
world = v.get()
global world
print world
Label(root, text="""How many pictures do you have left to scan?""", padx = 15).pack()
for txt, val in languages:
Radiobutton(root,
text=txt,
padx = 20,
variable=v,
command=ShowChoice,
value=val).pack(anchor=W)
mainloop()
Radiobutton(root,
text=txt,
indicatoron = 0,
width = 20,
padx = 20,
variable=v,
command=ShowChoice,
value=val).pack(anchor=W)
print 'The V get variable is: ' + world()