79 lines
3.1 KiB
Python
79 lines
3.1 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk
|
|
|
|
|
|
class StockApp:
|
|
def __init__(self, root):
|
|
self.root = root
|
|
self.root.title("股票数据查询")
|
|
self.root.geometry("900x600")
|
|
|
|
self.create_controls()
|
|
self.create_table()
|
|
self.load_sample_data()
|
|
|
|
# 配置布局权重
|
|
self.root.grid_rowconfigure(1, weight=1)
|
|
self.root.grid_columnconfigure(0, weight=1)
|
|
|
|
def create_controls(self):
|
|
"""创建顶部控制栏"""
|
|
t1_frame = ttk.Frame(self.root)
|
|
t2_frame = ttk.Frame(self.root)
|
|
t1_frame.grid(row=0, column=0, columnspan=6, padx=10, pady=10, sticky="nsew")
|
|
t2_frame.grid(row=1, column=0, columnspan=6, padx=10, pady=10, sticky="nsew")
|
|
|
|
# 年份选择
|
|
self.year_label = ttk.Label(t1_frame, text="选择年份:")
|
|
self.year_label.grid(row=0, column=0, padx=10, pady=10, sticky="w")
|
|
self.year_combobox = ttk.Combobox(t1_frame, values=["2023", "2024", "2025"], width=8)
|
|
self.year_combobox.grid(row=0, column=1, padx=10, pady=10, sticky="w")
|
|
self.year_combobox.set("2025")
|
|
|
|
# 月份选择
|
|
self.month_label = ttk.Label(t1_frame, text="选择月份:")
|
|
self.month_label.grid(row=0, column=2, padx=10, pady=10, sticky="w")
|
|
self.month_combobox = ttk.Combobox(t1_frame, values=[f"{i:02d}" for i in range(1, 13)], width=8)
|
|
self.month_combobox.grid(row=0, column=3, padx=10, pady=10, sticky="w")
|
|
|
|
# 日期选择
|
|
self.date_label = ttk.Label(t1_frame, text="选择日期:")
|
|
self.date_label.grid(row=0, column=4, padx=10, pady=10, sticky="w")
|
|
self.date_combobox = ttk.Combobox(t1_frame, values=[f"{i:02d}" for i in range(1, 32)], width=8)
|
|
self.date_combobox.grid(row=0, column=5, padx=10, pady=10, sticky="w")
|
|
|
|
columns = ("代码", "名称", "目标价", "次日开盘价", "开盘涨幅",
|
|
"卖出最高价", "是否错买", "当日盈亏", "卖出盈亏")
|
|
self.tree = ttk.Treeview(t2_frame, columns=columns, show="headings", height=20)
|
|
self.tree.grid(row=1, column=0, columnspan=6, padx=10, pady=10, sticky="nsew")
|
|
|
|
def create_table(self):
|
|
"""创建表格组件"""
|
|
columns = ("代码", "名称", "目标价", "次日开盘价", "开盘涨幅",
|
|
"卖出最高价", "是否错买", "当日盈亏", "卖出盈亏")
|
|
|
|
|
|
# 设置列宽
|
|
col_widths = [80, 100, 80, 100, 80, 100, 80, 80, 80]
|
|
for col, width in zip(columns, col_widths):
|
|
self.tree.heading(col, text=col)
|
|
self.tree.column(col, width=width, anchor="center")
|
|
|
|
|
|
|
|
def load_sample_data(self):
|
|
"""加载示例数据"""
|
|
sample_data = [
|
|
("600519", "贵州茅台", "1800.00", "1785.00", "-0.83%",
|
|
"1799.00", "否", "+0.78%", "+1.12%"),
|
|
("000001", "平安银行", "15.30", "15.20", "-0.65%",
|
|
"15.50", "是", "-0.33%", "+1.31%")
|
|
]
|
|
for data in sample_data:
|
|
self.tree.insert("", "end", values=data)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
root = tk.Tk()
|
|
app = StockApp(root)
|
|
root.mainloop() |