You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
5.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# FH的python代码
# 文本分析和图像识别
# 开发时间 2023/7/17 15:52
# 创建主窗口
import fractaltree1
import tkinter as tk
import tkinter.font as tf
root = tk.Tk()
w = root.winfo_screenwidth()
h = root.winfo_screenheight()
root.geometry("%dx%d" % (w, h))
root.title("分形树 电脑的分辨率是%dx%d" % (root.winfo_screenwidth(), root.winfo_screenheight()))
# 创建新增分形图案类型所需的字典
str_params_dict = {}
pattern_dict = {}
tree_dict = {}
update_params_dict = {}
# 定义变量,用于存储用户选择的分形类型
shape_var = tk.StringVar()
# 设置字体
ft1 = tf.Font(family="黑体", size=21)
ft2 = tf.Font(family="黑体", size=21, weight=tf.BOLD)
ft3 = tf.Font(family="黑体", size=18)
ft4 = tf.Font(family="黑体", size=19)
# 创建一个标签
lab1 = tk.Label(root, text="分形图案类型", font=ft1)
lab1.place(x=20, y=10, width=180, height=50, anchor='nw')
def add_fractal():
# 创建一个按钮,用来新增分形图案类型
button_addPattern = tk.Button(root, text="新增分形图案类型", command=add_fractal, font=ft2)
button_addPattern.place(x=500, y=10, width=270, height=50, anchor='ne')
## 滚动框的设置
# 创建一个Canvas对象使用该对象作为滚动区域
canvas = tk.Canvas(root, width=445, height=160)
# 创建一个列表框对象Rlist并将其放入滚动区域中
Rlist = tk.Listbox(canvas, width=445, height=20, bg='white', highlightthickness=1, highlightbackground="LightBlue")
# 创建滚动条对象并与Canvas绑定实现滚动条功能
scrollbar = tk.Scrollbar(root, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=scrollbar.set)
canvas.place(x=20, y=75, anchor='nw')
scrollbar.place(x=470, y=75, width=30, height=160, anchor='nw')
# 创建一个Frame组件用于放置单选框
frame = tk.Frame(Rlist, bg='white')
frame.place(anchor='nw')
# 将列表框放入Canvas中并设置Canvas窗口的大小
box_id = canvas.create_window((0, 0), window=Rlist, anchor="nw")
Rlist.update_idletasks() # 更新视图
canvas.config(scrollregion=canvas.bbox("all")) # 设置画布的滚动区域
# 添加单选框到 Frame组件
rb_Y = tk.Radiobutton(frame, text="Y形分形 Y_Fractal", variable=shape_var, value='Y', bg="white", font=ft1)
rb_Y.pack(anchor='w')
rb_Triangle = tk.Radiobutton(frame, text="三角形分形 Triangle_Fractal", variable=shape_var, value='Triangle',bg="white", font=ft1)
rb_Triangle.pack(anchor='w')
rb_Rect = tk.Radiobutton(frame, text="矩形分形 Rect_Fractal", variable=shape_var, value='Rect', bg="white", font=ft1)
rb_Rect.pack(anchor='w')
from fractaltree1 import pd
import os
if os.path.exists('params.csv'):
df=pd.read_csv("params.csv")
for i in df["分型名称"]:
rb1=tk.Radiobutton(frame,text=i,variable=shape_var,value=df[df['分型名称']==i].分形英文.values[0], bg="white", font=ft1)
rb1.pack(anchor='w')
# 将默认选项设置为 Y 形分形
rb_Y.select()
# 创建一个标签
lab2 = tk.Label(root, text="分形参数设置【参数含义:参量名=参量值】", font=ft4)
lab2.place(x=20, y=255, width=490, height=40, anchor='nw')
# 大画布的宽度和高度变量,方便后期调整
big_width = 880
big_height = 690
# 创建蓝色边框的大画布
cv_big = tk.Canvas(root, bg="white", highlightthickness=1, highlightbackground="LightBlue")
cv_big.config(width=big_width, height=big_height)
cv_big.place(x=530, y=10, anchor='nw')
# 创建红色边框的小画布宽高设置为大画布的1/4
cv_small = tk.Canvas(cv_big, bg="white", highlightthickness=1, highlightbackground="tomato")
cv_small.config(width=big_width * 0.25, height=big_height * 0.25)
cv_small.place(x=0, y=big_height, anchor='sw')
#创建一个多行文本框
params_text = tk.Text(root, bg="white", highlightthickness=1, highlightbackground="LightBlue")
params_text.configure(font=ft3, spacing1=15)
params_text.place(x=20, y=300, width=480, height=310, anchor='nw')
from fractaltree1 import params_Y
# 初始化分形参数并输出
params_str = params_Y
params_text.insert(tk.INSERT, params_str)
from fractaltree1 import update_Text
# trace追踪变量w模式回调函数update_text
shape_var.trace('w', lambda *args, str_params_dict=str_params_dict: update_Text())
from fractaltree1 import delete_rb
from fractaltree1 import draw_pattern
from fractaltree1 import update_params
from fractaltree1 import draw_tree
# 创建四个按钮
button_delete = tk.Button(root, text="删除\n选项", command=delete_rb, font=ft2)
button_delete.place(x=20, y=700, width=90, height=75, anchor='sw')
button_pattern = tk.Button(root, text="基本图\n案绘制", command=draw_pattern, font=ft2)
button_pattern.place(x=130, y=700, width=120, height=75, anchor='sw')
button_params = tk.Button(root, text="绘制参\n数设置", command=update_params, font=ft2)
button_params.place(x=270, y=700, width=120, height=75, anchor='sw')
button_drawTree = tk.Button(root, text="绘制", command=draw_tree, font=ft2)
button_drawTree.place(x=410, y=700, width=90, height=75, anchor='sw')