python版
代码:
import tkinter as tk
from tkinter import ttk, messagebox
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from datetime import datetime
class StockDesigner:
def __init__(self, root):
self.root = root
self.root.title("股票交易计算器")
self.root.geometry("1000x700")
# 设置主题样式
style = ttk.Style()
style.theme_use('clam') # 使用 clam 主题
# 自定义样式
style.configure('TLabel', font=('微软雅黑', 10))
style.configure('TButton', font=('微软雅黑', 10))
style.configure('TLabelframe', font=('微软雅黑', 10))
style.configure('TLabelframe.Label', font=('微软雅黑', 10, 'bold'))
style.configure('Custom.TButton', padding=10, font=('微软雅黑', 10, 'bold'))
# 设置默认手续费率
self.commission_rate = 0.00025
self.stamp_duty = 0.001
self.min_commission = 5
# 创建主框架
self.main_frame = ttk.Frame(root, padding="20")
self.main_frame.grid(row=0, column=0, sticky="nsew")
self.create_widgets()
# 配置根窗口的网格权重
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
def create_widgets(self):
# 创建标题
title_label = ttk.Label(self.main_frame, text="股票交易计算器",
font=('微软雅黑', 16, 'bold'))
title_label.grid(row=0, column=0, columnspan=2, pady=(0, 20))
# 创建左侧输入框架
input_frame = ttk.LabelFrame(self.main_frame, text="交易数据输入", padding="20")
input_frame.grid(row=1, column=0, padx=(0, 10), sticky="nsew")
# 修改输入框布局
labels = ["股票代码:", "买入价格:", "买入数量:", "目标卖出价:", "目标盈利金额:"]
entries = ["code_entry", "buy_price_entry", "volume_entry", "sell_price_entry", "target_profit_entry"]
for i, (label, entry) in enumerate(zip(labels, entries)):
ttk.Label(input_frame, text=label).grid(row=i, column=0, pady=10, padx=(0, 10), sticky="e")
entry_widget = ttk.Entry(input_frame, width=25, font=('微软雅黑', 10))
entry_widget.grid(row=i, column=1, pady=10, sticky="w")
setattr(self, entry, entry_widget)
# 添加说明文本
hint_text = "注:手续费率为万分之2.5,印花税为千分之1"
ttk.Label(input_frame, text=hint_text, font=('微软雅黑', 9), foreground='gray')\