用单选按钮Label输出
使用窗体,控件
from tkinter import *
def main():
def calc():
num=int(t1.get())
sel=v.get()
tn=['东方明珠','野生动物园','科技馆']
p=[160,130,60]
if (num >50):
s='购%s票%s张,票价%0.2f元' %(tn[int(sel)],num,num*p[int(sel)]*0.8)
elif (num >20):
s='购%s票%s张,票价%0.2f元' %(tn[int(sel)],num,num*p[int(sel)]*0.9)
else:
s='购%s票%s张,票价%0.2f元' %(tn[int(sel)],num,num*p[int(sel)])
lb3.config(text=s)
#创建窗体
root=Tk()
root.title('景点购票')
#创建控件
Label(root, text="请选择景点:").grid(row=0)
v = IntVar()
rd1=Radiobutton(root,text="东方明珠", variable=v, value=0)
rd1.grid(row=1)
rd2=Radiobutton(root,text="野生动物园", variable=v, value=1)
rd2.grid(row=2)
rd3=Radiobutton(root,text="科技馆", variable=v, value=2)
rd3.grid(row=3)
Label(root, text="请输入购票张数:").grid(row=4)
t1=Entry(root)
t1.grid(row=5)
Button(root,text='计算',command=calc).grid(row=6)
lb3=Label(root,text='结果记录')
lb3.grid(row=7)
#主窗体循环
root.mainloop()
if __name__=='__main__':
main()
输出结果:
文章评论