求求大佬有会“购电影票”这题吗?求求了救救孩子吧
一个购当场电影票程序,按照不同片名和购票张数,计算需付费金额:邪不压正(单价28.5元/张),我不是药神(单价31.0元/张),西虹市首富(单价46.0元/张)。用单选按钮选择片名,并在输入框中输入购票数量,单击'计算'按钮,将在结果标签中显示选择片名、购票数量及需付费金额。公式为:
需付费金额=影片单价 × 购票张数
需要界面吗
或者说那种界面
tkinter ,pyqt? c语言? 王之叹息 发表于 2021-5-26 07:06
c语言?
好吧,打扰了 python tkinter
import tkinter as tk
movie_dict = {'邪不压正':28.5,'我不是药神':31.0,'西虹市首富':46.0}
movies = [(list(movie_dict.keys()),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
num = all_list.get()
if not num.isdigit():
string = '请输入正整数'
else:
num = int(num)
price = num * movie_dict
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()
小伤口 发表于 2021-5-26 00:48
需要界面吗
或者说那种界面
tkinter ,pyqt?
对滴
页:
[1]