要使用Python生成窗口并进行布局,可以使用Tkinter库。下面是一个示例代码,实现了你的要求:

import tkinter as tk

def calculate():
    weight = float(weight_entry.get())
    cost = float(cost_entry.get())
    discount = float(discount_entry.get())
    profit_margin = float(profit_margin_entry.get())
    exchange_rate = float(exchange_rate_entry.get())
    commission = float(commission_entry.get())
    
    # 计算逻辑
    # ...

    # 显示输出内容
    output_text.delete('1.0', tk.END)
    output_text.insert(tk.END, '计算结果:\n')
    # ...

root = tk.Tk()

# 设置窗口大小和标题
root.geometry('400x300')
root.title('Calculation Window')

# 创建输入框和标签
weight_label = tk.Label(root, text='克重:')
weight_label.pack(side=tk.LEFT)
weight_entry = tk.Entry(root)
weight_entry.pack(side=tk.LEFT)

cost_label = tk.Label(root, text='成本:')
cost_label.pack(side=tk.LEFT)
cost_entry = tk.Entry(root)
cost_entry.pack(side=tk.LEFT)

discount_label = tk.Label(root, text='折扣率:')
discount_label.pack(side=tk.LEFT)
discount_entry = tk.Entry(root)
discount_entry.pack(side=tk.LEFT)

profit_margin_label = tk.Label(root, text='利润率:')
profit_margin_label.pack(side=tk.LEFT)
profit_margin_entry = tk.Entry(root)
profit_margin_entry.pack(side=tk.LEFT)

exchange_rate_label = tk.Label(root, text='汇率:')
exchange_rate_label.pack(side=tk.LEFT)
exchange_rate_entry = tk.Entry(root)
exchange_rate_entry.pack(side=tk.LEFT)

commission_label = tk.Label(root, text='平台佣金:')
commission_label.pack(side=tk.LEFT)
commission_entry = tk.Entry(root)
commission_entry.pack(side=tk.LEFT)

# 创建计算按钮
calculate_button = tk.Button(root, text='计算', command=calculate)
calculate_button.pack(side=tk.TOP)

# 创建输出屏幕
output_text = tk.Text(root, height=10, width=30)
output_text.pack(side=tk.BOTTOM)

root.mainloop()

在这个示例中,我们使用了tk.Label来创建标签,tk.Entry来创建输入框,tk.Button来创建计算按钮,tk.Text来创建输出屏幕。使用pack方法将它们按照横向布局方式依次放置在窗口中。

你可以根据需要进行修改和添加计算逻辑。

使用Python Tkinter 创建计算窗口 - 带输入框和输出屏幕

原文地址: https://www.cveoy.top/t/topic/oXWg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录