tkiner将字典用在单选上

tkiner将字典用在单选上_第1张图片

 1 from tkinter import *
 2 def printSelection():
 3     print(cities[int(var.get())])
 4     lab.config(text="你选择了"+cities[int(var.get())])
 5 
 6 root = Tk()
 7 root.title("tkiner将字典用在单选上")
 8 
 9 cities ={0:"西瓜",1:"苹果",2:"草莓",3:"香蕉",4:"菠萝"}
10 
11 var = IntVar()
12 var.set(0)
13 
14 lab = Label(root,text="选择你喜欢的水果",fg="blue",bg="lightyellow",width=30)
15 lab.pack()
16 
17 for val,city in cities.items():
18     Radiobutton(root,text=city,variable=var,value=val,
19                #位置1
20                 command=printSelection).pack()
21 root.mainloop()

 

tkiner将字典用在单选上_第2张图片

#位置1 加入代码: indicatoron=0,width=30,

你可能感兴趣的:(tkiner将字典用在单选上)