tkiner将字典用在单选上 Python 第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()

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

tkiner将字典用在单选上 Python 第2张

#位置1 加入代码: indicatoron=0,width=30,
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄