下载地址:https://www.pan38.com/dow/share.php?code=JCnzE 提取密码:1133
这个代码创建了一个简单的淘宝订单界面模拟器,使用了tkinter库来构建GUI界面。程序会随机生成订单信息、商品信息和总金额。请注意这只是一个界面模拟器,不会生成真实的订单截图,仅供学习Python GUI编程使用。
如果您需要学习Python GUI编程,可以深入研究tkinter、PyQt等库,或者学习图像处理库如Pillow来创建更复杂的界面效果。
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk
import random
from datetime import datetime, timedelta
class TaobaoOrderSimulator:
def init(self, root):
self.root = root
self.root.title("淘宝订单模拟器")
self.root.geometry("800x600")
# 模拟数据
self.products = [
{"name": "夏季新款男士短袖T恤", "price": 89.0, "image": "tshirt.png"},
{"name": "无线蓝牙耳机", "price": 199.0, "image": "earphone.png"},
{"name": "智能手机", "price": 2999.0, "image": "phone.png"},
{"name": "笔记本电脑", "price": 5999.0, "image": "laptop.png"},
{"name": "运动鞋", "price": 259.0, "image": "shoes.png"}
]
self.create_widgets()
def create_widgets(self):
# 顶部标题
title_frame = tk.Frame(self.root)
title_frame.pack(pady=10)
tk.Label(title_frame, text="淘宝订单详情", font=("微软雅黑", 16, "bold")).pack()
# 订单信息
info_frame = tk.Frame(self.root)
info_frame.pack(pady=10, padx=20, fill=tk.X)
# 随机生成订单信息
order_id = "TB" + "".join([str(random.randint(0, 9)) for _ in range(15)])
order_time = datetime.now() - timedelta(days=random.randint(0, 30))
tk.Label(info_frame, text=f"订单编号: {order_id}", font=("微软雅黑", 10)).grid(row=0, column=0, sticky="w")
tk.Label(info_frame, text=f"创建时间: {order_time.strftime('%Y-%m-%d %H:%M:%S')}", font=("微软雅黑", 10)).grid(row=1, column=0, sticky="w")
tk.Label(info_frame, text="订单状态: 交易成功", font=("微软雅黑", 10)).grid(row=2, column=0, sticky="w")
# 商品列表
product_frame = tk.Frame(self.root)
product_frame.pack(pady=10, padx=20, fill=tk.BOTH, expand=True)
# 表头
headers = ["商品", "单价", "数量", "小计"]
for i, header in enumerate(headers):
tk.Label(product_frame, text=header, font=("微软雅黑", 10, "bold")).grid(row=0, column=i, padx=5, pady=5)
# 随机选择1-3个商品
selected_products = random.sample(self.products, random.randint(1, 3))
total_amount = 0
for i, product in enumerate(selected_products, start=1):
quantity = random.randint(1, 3)
subtotal = product["price"] * quantity
total_amount += subtotal
# 商品图片和名称
try:
img = Image.open(product["image"])
img = img.resize((50, 50), Image.ANTIALIAS)
photo = ImageTk.PhotoImage(img)
img_label = tk.Label(product_frame, image=photo)
img_label.image = photo
img_label.grid(row=i, column=0, padx=5, pady=5, sticky="w")
except:
pass
tk.Label(product_frame, text=product["name"], font=("微软雅黑", 10)).grid(row=i, column=0, padx=60, pady=5, sticky="w")
# 单价
tk.Label(product_frame, text=f"¥{product['price']:.2f}", font=("微软雅黑", 10)).grid(row=i, column=1, padx=5, pady=5)
# 数量
tk.Label(product_frame, text=str(quantity), font=("微软雅黑", 10)).grid(row=i, column=2, padx=5, pady=5)
# 小计
tk.Label(product_frame, text=f"¥{subtotal:.2f}", font=("微软雅黑", 10)).grid(row=i, column=3, padx=5, pady=5)
# 总计
total_frame = tk.Frame(self.root)
total_frame.pack(pady=10, padx=20, fill=tk.X)
tk.Label(total_frame, text="实付款:", font=("微软雅黑", 12)).pack(side=tk.LEFT)
tk.Label(total_frame, text=f"¥{total_amount:.2f}", font=("微软雅黑", 12, "bold"), fg="red").pack(side=tk.LEFT, padx=5)
# 底部按钮
button_frame = tk.Frame(self.root)
button_frame.pack(pady=20)
tk.Button(button_frame, text="返回订单列表", width=15).pack(side=tk.LEFT, padx=10)
tk.Button(button_frame, text="联系卖家", width=15).pack(side=tk.LEFT, padx=10)
tk.Button(button_frame, text="再次购买", width=15).pack(side=tk.LEFT, padx=10)
if name == "main":
root = tk.Tk()
app = TaobaoOrderSimulator(root)
root.mainloop()