import tkinter as tk
movie_dict = {'邪不压正':28.5,'我不是药神':31.0,'西虹市首富':46.0}
movies = [(list(movie_dict.keys())[num-1],num) for num in range(0,3)]
master = tk.Tk()
var = tk.IntVar()
row = 0
all_list=[]
for movie,num in movies:
b = tk.Radiobutton(master, text=movie, variable=var,value=num)
b.grid(row=row, column=1, sticky=tk.W)
e = tk.Entry(master,width=5,)
e.grid(row=row, column=2, sticky=tk.E)
w = tk.Label(master,text='张')
w.grid(row=row, column=3, sticky=tk.E)
all_list.append(e)
row+=1
def show():
end = tk.Label(master,text='',height=2,width=20)
end.grid(row=row+1, column=1,columnspan=3,rowspan=2, sticky=tk.W)
movie = movies[var.get()][0]
num = all_list[var.get()].get()
if not num.isdigit():
string = '请输入正整数'
else:
num = int(num)
price = num * movie_dict[movie]
string = f'《{movie}》 共{num}张 \n合计{price}元'
end = tk.Label(master,text=string,height=2,width=20)
end.grid(row=row+1, column=1,columnspan=3,rowspan=2, sticky=tk.W)
tk.Button(master, text="计算", width=10, command=show).grid(row=row, column=1, sticky=tk.W, padx=10, pady=5)
end = tk.Label(master,text='',height=2,width=20)
end.grid(row=row+1, column=1,columnspan=3,rowspan=2, sticky=tk.W)
tk.mainloop()