计算程序已经写好,需要写一个ui并生成exe
需要用tkinter写一个程序的ui,然后生成exe
import tkinter as tk
import pandas as pd
import re
window = tk.Tk()
window.title('价格计算程序')
window.geometry('500x250')#乘号是字母x
e = tk.Entry(window,show=None)
e.pack()
detail = e.get()
def shuru():
data = pd.read_excel(r'C:\Users\Administrator\Desktop\价格别名表.xlsx', sheet_name=0) # 读取表格原始数据
# 提取表格中每一列的数据
name1 = data['名称']
# 价格的单位为克
price1 = data['价格1']
price2 = data['价格2']
price3 = data['价格3']
alias = data['别名']
test = re.findall('([\u4e00-\u9fa5A-Za-z]+)(\d+)([\u4e00-\u9fa5A-Za-z]+)', detail)
# print(test)
name = [x[0] for x in test]
num = [int(x[1]) for x in test]
unit = [x[2] for x in test]
index = range(1, len(test) + 1)
jiage = []
amount = []
for i in range(len(name)):
price = None
amo = None
for j in range(len(name1)):
sl = alias[j].strip().split('、')
if any(map(lambda x: x in name[i], sl)):
name[i] = sl[0]
if num[i] >= 250:
price = price1[j]
elif 100 < num[i] < 250:
price = price2[j]
else:
price = price3[j]
amo = num[i] / 500 * price
break
else:
print('没找到', name[i])
jiage.append(price)
amount.append(amo)
# 3.创建字典
data = {
"序号": index,
"名称": name,
"重量": num,
"单位": unit,
"价格": jiage,
'金额': amount
}
# 4.创建DataFrame表格
df = pd.DataFrame(data)
# print(df)
# 5.写入excel
df.to_excel(r'C:\Users\Administrator\Desktop\结果.xlsx', index=None)
b = tk.Button(window,text='点击此处进行计算',width=12,height=2,command=shuru)
b.pack()
window.mainloop()