diff --git a/20230509-函数绘制.docx b/20230509-函数绘制.docx deleted file mode 100644 index d5ecb47..0000000 Binary files a/20230509-函数绘制.docx and /dev/null differ diff --git a/20230701计算思维程序实践-第3章 数值计算与曲线绘制.docx b/20230701计算思维程序实践-第3章 数值计算与曲线绘制.docx new file mode 100644 index 0000000..b98eb60 Binary files /dev/null and b/20230701计算思维程序实践-第3章 数值计算与曲线绘制.docx differ diff --git a/__pycache__/functionUtil.cpython-37.pyc b/__pycache__/functionUtil.cpython-37.pyc new file mode 100644 index 0000000..dddde80 Binary files /dev/null and b/__pycache__/functionUtil.cpython-37.pyc differ diff --git a/__pycache__/functionUtil.cpython-39.pyc b/__pycache__/functionUtil.cpython-39.pyc new file mode 100644 index 0000000..f242341 Binary files /dev/null and b/__pycache__/functionUtil.cpython-39.pyc differ diff --git a/image/下部背景.png b/image/下部背景.png new file mode 100644 index 0000000..f610758 Binary files /dev/null and b/image/下部背景.png differ diff --git a/image/下部背景@2x.png b/image/下部背景@2x.png new file mode 100644 index 0000000..4117a49 Binary files /dev/null and b/image/下部背景@2x.png differ diff --git a/image/下部背景@3x.png b/image/下部背景@3x.png new file mode 100644 index 0000000..ec4b13e Binary files /dev/null and b/image/下部背景@3x.png differ diff --git a/image/勾选.png b/image/勾选.png new file mode 100644 index 0000000..1f79713 Binary files /dev/null and b/image/勾选.png differ diff --git a/image/勾选@2x.png b/image/勾选@2x.png new file mode 100644 index 0000000..218acdd Binary files /dev/null and b/image/勾选@2x.png differ diff --git a/image/勾选@3x.png b/image/勾选@3x.png new file mode 100644 index 0000000..7188964 Binary files /dev/null and b/image/勾选@3x.png differ diff --git a/image/勾选选中.png b/image/勾选选中.png new file mode 100644 index 0000000..7924490 Binary files /dev/null and b/image/勾选选中.png differ diff --git a/image/勾选选中@2x.png b/image/勾选选中@2x.png new file mode 100644 index 0000000..43afa0c Binary files /dev/null and b/image/勾选选中@2x.png differ diff --git a/image/勾选选中@3x.png b/image/勾选选中@3x.png new file mode 100644 index 0000000..7851730 Binary files /dev/null and b/image/勾选选中@3x.png differ diff --git a/image/右侧背景.png b/image/右侧背景.png new file mode 100644 index 0000000..98e4b89 Binary files /dev/null and b/image/右侧背景.png differ diff --git a/image/右侧背景@2x.png b/image/右侧背景@2x.png new file mode 100644 index 0000000..d508637 Binary files /dev/null and b/image/右侧背景@2x.png differ diff --git a/image/右侧背景@3x.png b/image/右侧背景@3x.png new file mode 100644 index 0000000..7de0099 Binary files /dev/null and b/image/右侧背景@3x.png differ diff --git a/image/导航背景.jpg b/image/导航背景.jpg new file mode 100644 index 0000000..275a004 Binary files /dev/null and b/image/导航背景.jpg differ diff --git a/image/导航背景@2x.png b/image/导航背景@2x.png new file mode 100644 index 0000000..5122889 Binary files /dev/null and b/image/导航背景@2x.png differ diff --git a/image/导航背景@3x.png b/image/导航背景@3x.png new file mode 100644 index 0000000..981a4b6 Binary files /dev/null and b/image/导航背景@3x.png differ diff --git a/image/文字背景.png b/image/文字背景.png new file mode 100644 index 0000000..83d3134 Binary files /dev/null and b/image/文字背景.png differ diff --git a/image/文字背景2.png b/image/文字背景2.png new file mode 100644 index 0000000..a114b1d Binary files /dev/null and b/image/文字背景2.png differ diff --git a/image/文字背景2@2x.png b/image/文字背景2@2x.png new file mode 100644 index 0000000..c7126bd Binary files /dev/null and b/image/文字背景2@2x.png differ diff --git a/image/文字背景2@3x.png b/image/文字背景2@3x.png new file mode 100644 index 0000000..267e8ef Binary files /dev/null and b/image/文字背景2@3x.png differ diff --git a/image/文字背景@2x.png b/image/文字背景@2x.png new file mode 100644 index 0000000..9f976a6 Binary files /dev/null and b/image/文字背景@2x.png differ diff --git a/image/文字背景@3x.png b/image/文字背景@3x.png new file mode 100644 index 0000000..0c911a8 Binary files /dev/null and b/image/文字背景@3x.png differ diff --git a/image/用户命名并新增基本函数-点击.png b/image/用户命名并新增基本函数-点击.png new file mode 100644 index 0000000..5c4b86b Binary files /dev/null and b/image/用户命名并新增基本函数-点击.png differ diff --git a/image/用户命名并新增基本函数-点击@2x.png b/image/用户命名并新增基本函数-点击@2x.png new file mode 100644 index 0000000..56a9e14 Binary files /dev/null and b/image/用户命名并新增基本函数-点击@2x.png differ diff --git a/image/用户命名并新增基本函数-点击@3x.png b/image/用户命名并新增基本函数-点击@3x.png new file mode 100644 index 0000000..bb3cfa1 Binary files /dev/null and b/image/用户命名并新增基本函数-点击@3x.png differ diff --git a/image/用户命名并新增基本函数.png b/image/用户命名并新增基本函数.png new file mode 100644 index 0000000..1e0f408 Binary files /dev/null and b/image/用户命名并新增基本函数.png differ diff --git a/image/用户命名并新增基本函数@2x.png b/image/用户命名并新增基本函数@2x.png new file mode 100644 index 0000000..453249f Binary files /dev/null and b/image/用户命名并新增基本函数@2x.png differ diff --git a/image/用户命名并新增基本函数@3x.png b/image/用户命名并新增基本函数@3x.png new file mode 100644 index 0000000..1546a58 Binary files /dev/null and b/image/用户命名并新增基本函数@3x.png differ diff --git a/image/背景.jpg b/image/背景.jpg new file mode 100644 index 0000000..6f0af51 Binary files /dev/null and b/image/背景.jpg differ diff --git a/image/背景@2x.jpg b/image/背景@2x.jpg new file mode 100644 index 0000000..365e47c Binary files /dev/null and b/image/背景@2x.jpg differ diff --git a/image/背景@3x.jpg b/image/背景@3x.jpg new file mode 100644 index 0000000..356fb09 Binary files /dev/null and b/image/背景@3x.jpg differ diff --git a/image/象限选择背景.png b/image/象限选择背景.png new file mode 100644 index 0000000..1ca972a Binary files /dev/null and b/image/象限选择背景.png differ diff --git a/image/象限选择背景@2x.png b/image/象限选择背景@2x.png new file mode 100644 index 0000000..c8f5b25 Binary files /dev/null and b/image/象限选择背景@2x.png differ diff --git a/image/象限选择背景@3x.png b/image/象限选择背景@3x.png new file mode 100644 index 0000000..23c9601 Binary files /dev/null and b/image/象限选择背景@3x.png differ diff --git a/image/输入条.png b/image/输入条.png new file mode 100644 index 0000000..adf0782 Binary files /dev/null and b/image/输入条.png differ diff --git a/image/输入条@2x.png b/image/输入条@2x.png new file mode 100644 index 0000000..b2867de Binary files /dev/null and b/image/输入条@2x.png differ diff --git a/image/输入条@3x.png b/image/输入条@3x.png new file mode 100644 index 0000000..abafd68 Binary files /dev/null and b/image/输入条@3x.png differ diff --git a/image/输出-点击.png b/image/输出-点击.png new file mode 100644 index 0000000..0d06be3 Binary files /dev/null and b/image/输出-点击.png differ diff --git a/image/输出-点击@2x.png b/image/输出-点击@2x.png new file mode 100644 index 0000000..26c0c5a Binary files /dev/null and b/image/输出-点击@2x.png differ diff --git a/image/输出-点击@3x.png b/image/输出-点击@3x.png new file mode 100644 index 0000000..dc6f3ad Binary files /dev/null and b/image/输出-点击@3x.png differ diff --git a/image/输出.png b/image/输出.png new file mode 100644 index 0000000..833da41 Binary files /dev/null and b/image/输出.png differ diff --git a/image/输出@2x.png b/image/输出@2x.png new file mode 100644 index 0000000..7f963ee Binary files /dev/null and b/image/输出@2x.png differ diff --git a/image/输出@3x.png b/image/输出@3x.png new file mode 100644 index 0000000..43357e1 Binary files /dev/null and b/image/输出@3x.png differ diff --git a/image/长条输入框.png b/image/长条输入框.png new file mode 100644 index 0000000..13031d2 Binary files /dev/null and b/image/长条输入框.png differ diff --git a/image/长条输入框@2x.png b/image/长条输入框@2x.png new file mode 100644 index 0000000..e53671b Binary files /dev/null and b/image/长条输入框@2x.png differ diff --git a/image/长条输入框@3x.png b/image/长条输入框@3x.png new file mode 100644 index 0000000..006b8b8 Binary files /dev/null and b/image/长条输入框@3x.png differ diff --git a/step1/step.py b/step1/step.py new file mode 100644 index 0000000..51459ea --- /dev/null +++ b/step1/step.py @@ -0,0 +1 @@ +############### 请在右侧图形化界面,全屏展示界面,完成本关卡 ################### \ No newline at end of file diff --git a/step1/step1.sh b/step1/step1.sh new file mode 100644 index 0000000..94ae51e --- /dev/null +++ b/step1/step1.sh @@ -0,0 +1,6 @@ +xrandr --addmode VNC-0 "1920x1080" +xrandr --output VNC-0 --mode "1920x1080" +nohup python3 x5/FunctionDisplay_X5.py & +echo "编译成功" +echo "运行成功" +echo "测评成功" \ No newline at end of file diff --git a/text b/text new file mode 100644 index 0000000..cd513f6 --- /dev/null +++ b/text @@ -0,0 +1,26 @@ +self.func_input = Entry(bottom_frame, font=self.font_style, width=40) +self.func_input.grid(row=0, column=0, columnspan=6, padx=(15,0), pady=5) +self.add_func_button = Button(bottom_frame, text="用户命名并新增基本函数", command=self.add_function) +self.add_func_button.grid(row=0, column=6, columnspan=2,padx=10, pady=15, sticky="ne") +Label(bottom_frame, text="x步长", font=("Lucida Grande", 18)).place(x=15,y=80) +self.x_step = Entry(bottom_frame, font=self.font_style, width=10) +self.x_step.place(x=135, y=70, width=215,height=52) +Label(bottom_frame, text="x个数", font=("Lucida Grande", 18)).place(x=15,y=155) +self.x_count = Entry(bottom_frame, font=self.font_style, width=10) +self.x_count.place(x=135, y=150, width=215,height=52) + +Label(bottom_frame, text="坐标轴", font=("Lucida Grande", 20)).grid(row=2, column=4,padx=(150,0)) +self.quadrant = IntVar() +self.quadrant.set(4) +Radiobutton(bottom_frame, text="四象限", command=self.update_quadrant, + value=4, variable=self.quadrant).grid(row=1, column=5, sticky="sw",padx=(0,135)) +Radiobutton(bottom_frame, text="一象限", command=self.update_quadrant, + value=1, variable=self.quadrant).grid(row=3, column=5, sticky="nw",padx=(0,135)) +Label(bottom_frame, text="x放大倍数", font=("Lucida Grande", 18)).place(x=750,y=80) +self.x_scale = Entry(bottom_frame, font=self.font_style, width=10) +self.x_scale.grid(row=1, column=6, padx=(70,0), sticky="se") +Label(bottom_frame, text="y放大倍数", font=("Lucida Grande", 18)).place(x=750,y=160) +self.y_scale = Entry(bottom_frame, font=self.font_style, width=10) +self.y_scale.grid(row=3, column=6, sticky="ne") +Button(bottom_frame, text="输出", command=self.print_function, width=5) \ + .grid(row=1, rowspan=3, column=8, padx=(30,0),sticky="w") \ No newline at end of file diff --git a/x5_218/FunctionDisplay_X5.py b/x5/FunctionDisplay_X5.py similarity index 66% rename from x5_218/FunctionDisplay_X5.py rename to x5/FunctionDisplay_X5.py index d0cfbee..9aef5b4 100644 --- a/x5_218/FunctionDisplay_X5.py +++ b/x5/FunctionDisplay_X5.py @@ -1,5 +1,5 @@ from time import sleep -from ttkbootstrap import * +from tkinter import * import tkinter.font as tkFont from tkinter import messagebox @@ -12,7 +12,9 @@ from numpy import arange from sympy import symbols, lambdify from functionUtil import FunctionUtil - +import math +from PIL import ImageTk, Image +import sys # 在画布中央绘制文本 def center_text(canvas, text, font): @@ -26,16 +28,20 @@ class Graph(Canvas): """ 绘制函数图形 """ + def __init__(self, master=None, **kwargs): super().__init__(master, **kwargs) self.width = int(self.cget('width')) self.height = int(self.cget('height')) self.origin = (self.width / 2, self.height / 2) + self.config(bg="white") self.bili_x = 20 self.bili_y = 20 self.draw_axis() self.draw_scale() self.fig = FigureCanvasTkAgg() + self.y_scale = 1.0 + def draw_axis(self): """ @@ -77,6 +83,7 @@ class Graph(Canvas): self.draw_axis() self.draw_scale() + def draw_graph_3d(self, func, draw_precision=0.1, count=1000, bili_x=20, bili_y=40, ): self.fig.get_tk_widget().destroy() self.delete("all") @@ -93,16 +100,20 @@ class Graph(Canvas): X, Y = np.meshgrid(X, Y) Z = expr(X, Y) # 创建一个 Figure 对象 - fig = Figure(figsize=(5.5, 6), dpi=100) + fig = Figure(figsize=(7, 5.5), dpi=120) # 在 Figure 上创建一个 3D 子图 ax = fig.add_subplot(111, projection='3d') + ax.auto_scale_xyz(X, Y, Z) # 绘制三维图形 ax.plot_surface(X, Y, Z, cmap='viridis') self.fig = FigureCanvasTkAgg(fig, master=self) self.fig.draw() - self.fig.get_tk_widget().pack(fill=BOTH, ipadx=0, ipady=0, pady=0, padx=0) + self.fig.get_tk_widget().pack(fill=BOTH, ipadx=0, ipady=0, pady=0, padx=0, expand=True) + - def draw_graph(self, func, draw_precision=0.1, count=1000, bili_x=20, bili_y=40, c='blue'): + + + def draw_graph_2d(self, func, draw_precision=0.1, count=1000, bili_x=1, bili_y=1, c='blue'): 'xmin,xmax 自变量的取值范围; c 图像颜色' 'x0,y0 原点坐标 w,h 横纵轴半长 draw_precision 步进' self.fig.get_tk_widget().destroy() @@ -142,14 +153,14 @@ class Graph(Canvas): class ExpressionCanvas(Canvas): def __init__(self, master, *args, **kwargs): super().__init__(master, *args, **kwargs) - self.node_width = 60 - self.node_height = 30 - self.x_spacing = 10 + self.node_width = 100 + self.node_height = 40 + self.x_spacing = 15 self.y_spacing = 70 self.level = {} def add_node(self, text, x, y, parent=None): - node_width = len(text) * 5 + 20 + node_width = len(text) * 15 + 20 if node_width < 40: node_width = 50 # 创建节点 @@ -178,7 +189,7 @@ class ExpressionCanvas(Canvas): self.level[coords[1]].append(coords[2]) else: self.level[coords[1]] = [coords[2]] - text_id = self.create_text(x + 5, y + self.node_height // 2, text=text, anchor="center") + text_id = self.create_text(x + 5, y + self.node_height // 2, text=text, anchor="center", font=("", 15)) sleep(0.2) self.update() # 绘制父节点和当前节点的连线 @@ -208,14 +219,17 @@ class ExpressionCanvas(Canvas): return node -class FunctionDisplay(Frame): - def __init__(self, master, attr): - super().__init__(master) - self.attr = attr +class FunctionDisplay(Canvas): + def __init__(self, master, *args, **kwargs): + super().__init__(master, *args, **kwargs) self.font_style = tkFont.Font(family="Lucida Grande", size=30) self.functions = FunctionUtil() + self.width = int(self.cget("width")) + self.height = int(self.cget("height")) + self.background_img = ImageTk.PhotoImage(Image.open(sys.path[0]+"/./image/背景@3x.jpg").resize((self.width, self.height))) + self.create_image(0, 0, image=self.background_img, anchor=NW) self.master = master - self.create_window() + self.init_window() self.load_user_function() def add_function(self): @@ -286,9 +300,10 @@ class FunctionDisplay(Frame): def load_user_function(self): self.user_function_canvas.delete(ALL) - self.user_function_canvas.create_text(20 + 90, 35, text='可识别基本函数', fill='red', font=("Purisa", 20, "bold")) + self.user_function_canvas.create_text(20 + 90, 35, text='可识别基本函数', fill='red', + font=("Purisa", 20, "bold")) num = 2 - self.user_function_canvas.create_text(0, 70, anchor="nw", text="函数", font=("", 15)) + self.user_function_canvas.create_text(0, 70, anchor="nw", text="函数名", font=("", 15)) self.user_function_canvas.create_text(100, 70, anchor="nw", text="函数体", font=("", 15)) for function, function_body in self.functions.data.items(): self.user_function_canvas.create_text(0, 20 * num + 50, anchor="nw", text=function, font=("", 15)) @@ -298,86 +313,107 @@ class FunctionDisplay(Frame): self.user_function_canvas.configure(scrollregion=self.user_function_canvas.bbox("all")) def create_form(self): - bottom_frame = Frame(self.master, width=self.attr["width"], height=self.attr["height"] * 0.3) - self.func_input = Entry(bottom_frame, font=self.font_style, width=40) - self.func_input.grid(row=0, column=0, columnspan=4, padx=30) - self.add_func_button = Button(bottom_frame, text="用户命名并新增基本函数", command=self.add_function) - self.add_func_button.grid(row=0, column=4, padx=10) - Label(bottom_frame, text="x步长", font=("Lucida Grande", 20)).grid(row=1, column=0, padx=30) - self.x_step = Entry(bottom_frame, font=self.font_style, width=10) - self.x_step.grid(row=1, column=1, padx=10, pady=10) - Label(bottom_frame, text="x个数", font=("Lucida Grande", 20)).grid(row=1, column=2, padx=30) - self.x_count = Entry(bottom_frame, font=self.font_style, width=10) - self.x_count.grid(row=1, column=3, padx=10, pady=10) - - Label(bottom_frame, text="坐标轴", font=("Lucida Grande", 20)).grid(row=2, column=0, padx=30) + bottom_frame = Canvas(self, width=self.width, height=self.height * 0.3, highlightthickness=0) + self.back_image = ImageTk.PhotoImage(Image.open(sys.path[0]+"/./image/下部背景@3x.png").resize((self.width, int(self.height * 0.3)))) + bottom_frame.create_image(0, 0, image=self.back_image, anchor=NW) + label_width, entry_width, label_margin_left, margin_left, height, margin_top = 100, 215, 120 + 50, 120, 42, 20 + self.func_input = Entry(bottom_frame, font=self.font_style) + self.func_input.place(x=margin_left, y=margin_top, anchor=NW, width=1000, height=height) + self.add_func_image = ImageTk.PhotoImage(Image.open(sys.path[0]+"/./image/用户命名并新增基本函数@3x.png").resize((150, 42))) + self.add_func_button = Button(bottom_frame, image=self.add_func_image, bd=0, relief="solid", bg="#f7f7f7", + highlightthickness=0, command=self.add_function) + self.add_func_button.place(x=1140, y=20, anchor=NW) + + self.label_img = ImageTk.PhotoImage(Image.open(sys.path[0]+"/./image/文字背景@3x.png").resize((100, 42))) + bottom_frame.create_image(label_margin_left, 112, image=self.label_img) + bottom_frame.create_text(label_margin_left, 112, text="x步长", fill="white", font=("", 20)) + self.x_step = Entry(bottom_frame, font=self.font_style) + self.x_step.place(x=margin_left + label_width, y=112 - 21, width=215, height=42) + + self.label1_img = ImageTk.PhotoImage(Image.open(sys.path[0]+"/./image/文字背景@3x.png").resize((100, 42))) + bottom_frame.create_image(label_margin_left, 171, image=self.label1_img) + bottom_frame.create_text(label_margin_left, 170, text="x个数", fill="white", font=("", 20)) + self.x_count = Entry(bottom_frame, font=self.font_style) + self.x_count.place(x=margin_left + label_width, y=112 + 39, width=215, height=42) + + self.big_label_img = ImageTk.PhotoImage(Image.open(sys.path[0]+"/./image/文字背景2@3x.png").resize((label_width+5, height * 2 + margin_top))) + bottom_frame.create_image(label_margin_left + label_width + entry_width + 108, 112 + 31, image=self.big_label_img) + bottom_frame.create_text(label_margin_left + label_width + entry_width + 108, 112 + 31, text="坐标轴", fill="white", font=("", 25)) self.quadrant = IntVar() self.quadrant.set(4) - Radiobutton(bottom_frame, text="四象限", command=self.update_quadrant, - value=4, variable=self.quadrant).grid(row=2, column=1, padx=10, pady=10) - Radiobutton(bottom_frame, text="一象限", command=self.update_quadrant, - value=1, variable=self.quadrant).grid(row=2, column=2, padx=10, pady=10) - Label(bottom_frame, text="x放大倍数", font=("Lucida Grande", 20)).grid(row=3, column=0, padx=30) - self.x_scale = Entry(bottom_frame, font=self.font_style, width=10) - self.x_scale.grid(row=3, column=1, padx=10, pady=10) - Label(bottom_frame, text="y放大倍数", font=("Lucida Grande", 20)).grid(row=3, column=2, padx=30) - self.y_scale = Entry(bottom_frame, font=self.font_style, width=10) - self.y_scale.grid(row=3, column=3, padx=10, pady=10) - Button(bottom_frame, text="输出", command=self.print_function, width=5)\ - .grid(row=1, rowspan=3, column=4, sticky="w") - bottom_frame.place(x=0, y=self.attr["height"] * 0.65 + 20) - - def create_window(self): - self.axis_canvas = Graph(self.master, width=self.attr["width"] * 0.45, height=self.attr["height"] * 0.65, - bg="#cdcdcd") - self.axis_canvas.place(x=0, y=0) - self.text_canvas = ExpressionCanvas(self.master, width=self.attr["width"] * 0.35, - height=self.attr["height"] * 0.65, bg="#cdcdcd") - self.text_canvas.place(x=int(self.attr["width"] * 0.45), y=0) - user_function = Frame(self.master, width=self.attr["width"] * 0.2, height=self.attr["height"] * 0.65) - user_function.place(x=int(self.attr["width"] * 0.8), y=0) - self.user_function_canvas = Canvas(user_function, width=self.attr["width"] * 0.18, - height=self.attr["height"] * 0.63, background="#cdcdcd") + Radiobutton(bottom_frame, text="四象限", command=self.update_quadrant, font=("", 17), + bg="#b9b9f7",highlightthickness=0, highlightcolor="#aaaaf2", + value=4, variable=self.quadrant).place(x=label_margin_left + label_width * 2 + entry_width +58, y=90, + height=(height * 2 + margin_top) / 2, width=entry_width, anchor=NW) + Radiobutton(bottom_frame, text="一象限", command=self.update_quadrant, font=("", 17), bg="#b9b9f7", + highlightthickness=0, highlightcolor="#aaaaf2", + value=1, variable=self.quadrant).place(x=label_margin_left + label_width * 2 + entry_width +58, y=90 + (height * 2 + margin_top) / 2, + height=(height * 2 + margin_top) / 2, width=entry_width, anchor=NW) + + + + self.x_scale = Entry(bottom_frame, font=self.font_style) + self.x_scale.place(x=margin_left + label_width, y=112 - 21, width=215, height=42) + label_x = label_margin_left + 840 + label_y = 112 + self.label_img1 = ImageTk.PhotoImage(Image.open(sys.path[0]+"/./image/文字背景@3x.png").resize((130, 42))) + bottom_frame.create_image(label_x, label_y, image=self.label_img1) + bottom_frame.create_text(label_x, label_y, text="x放大倍数", fill="white", font=("", 20)) + entry_x = margin_left + label_width + 855 + entry_y = 112 - 21 + self.x_scale.place(x=entry_x, y=entry_y, width=215, height=42) + + + self.y_scale = Entry(bottom_frame, font=self.font_style) + self.y_scale.place(x=margin_left + label_width, y=112 - 21, width=215, height=42) + label_x = label_margin_left + 840 + label_y = 170 + bottom_frame.create_image(label_x, label_y, image=self.label_img1) + bottom_frame.create_text(label_x, label_y, text="y放大倍数", fill="white", font=("", 20)) + entry_x = margin_left + label_width + 855 + entry_y = 170 - 21 + self.y_scale.place(x=entry_x, y=entry_y, width=215, height=42) + + self.print_function_image = ImageTk.PhotoImage(Image.open(sys.path[0]+"/./image/输出-点击@3x.png").resize((100, 42))) + self.print_function_button = Button(bottom_frame, image=self.print_function_image, bd=0, relief="solid", bg="#f7f7f7", + highlightthickness=0, command=self.print_function) + self.print_function_button.place(x=1350, y=95, anchor=NW) + # Button(bottom_frame, text="输出", command=self.print_function, width=5) \ + # .place(x=1350, y=95, anchor=NW) + bottom_frame.place(x=0, y=self.height * 0.65 + 40, anchor=NW) + + def init_window(self): + self.axis_canvas = Graph(self, width=self.width * 0.45, height=self.height * 0.65,highlightthickness=0) + self.axis_canvas.place(x=0, y=0, anchor=NW) + self.text_canvas = ExpressionCanvas(self, width=self.width * 0.35, + height=self.height * 0.65, bg="white",highlightthickness=0) + self.text_canvas.place(x=int(self.width * 0.45), y=0) + user_function = Frame(self, width=self.width * 0.2, height=self.height * 0.65) + user_function.place(x=int(self.width * 0.8), y=0) + self.user_function_canvas = Canvas(user_function, width=self.width * 0.19, + height=self.height * 0.65, bg="white",highlightthickness=0) y_scrollbar = Scrollbar(user_function, orient="vertical", command=self.user_function_canvas.yview) x_scrollbar = Scrollbar(user_function, orient="horizontal", command=self.user_function_canvas.xview) x_scrollbar.pack(side=BOTTOM, fill=BOTH) y_scrollbar.pack(side=RIGHT, fill=BOTH) self.user_function_canvas.pack(side=TOP, fill=BOTH) self.user_function_canvas.config(yscrollcommand=y_scrollbar.set, xscrollcommand=x_scrollbar.set) - for i in range(1, 200): - self.user_function_canvas.create_text(80, i * 20 + 35, text="fdsaf{}".format(i)) self.user_function_canvas.config(scrollregion=self.user_function_canvas.bbox("all")) self.create_form() if __name__ == '__main__': - from pycallgraph2 import PyCallGraph - from pycallgraph2.output import GraphvizOutput - from pycallgraph2 import Config - from pycallgraph2 import GlobbingFilter - root = Window() + root = Tk() screenwidth = root.winfo_screenwidth() screenheight = root.winfo_screenheight() root_attr = { - "width": 1200, - "height": 800, + "width": int(screenwidth * 1), + "height": int(screenheight * 1), } alignstr = '%dx%d+%d+%d' % (root_attr['width'], root_attr['height'], (screenwidth - root_attr['width']) / 2, (screenheight - root_attr['height']) / 2) root.geometry(alignstr) root.resizable(width=False, height=False) - output = GraphvizOutput(font_size=30) - output.output_file = "basic.png" - output.group_font_size = 40 - config = Config() - config.trace_filter = GlobbingFilter(include=[ - 'FunctionDisplay.*', - 'Graph.*', - 'ExpressionCanvas.*', - 'FunctionUtil.*' - ]) - with PyCallGraph(output=output, config=config): - app = FunctionDisplay(root, root_attr) - ttk.Style().configure("TButton", font="-size 18") - ttk.Style().configure("TRadiobutton", font="-size 18") + app = FunctionDisplay(root, width=root_attr["width"], height=root_attr["height"]) + app.place(x=0, y=0, anchor=NW) root.mainloop() diff --git a/x5/basic.png b/x5/basic.png new file mode 100644 index 0000000..2fa5dc7 Binary files /dev/null and b/x5/basic.png differ diff --git a/x5/function.json b/x5/function.json new file mode 100644 index 0000000..901a7cf --- /dev/null +++ b/x5/function.json @@ -0,0 +1 @@ +{"xy": "x*y", "sinx": "sin(x)", "cosx": "cos(x)", "y": "sin(x)*cos(x)", "SinPlusCon": "sin(x)+cos(x)", "tanx": "tan(x)"} \ No newline at end of file diff --git a/x5/functionUtil.py b/x5/functionUtil.py new file mode 100644 index 0000000..09e52e3 --- /dev/null +++ b/x5/functionUtil.py @@ -0,0 +1,57 @@ +import json +import re + + +class FunctionUtil: + def __init__(self): + self.filename = "./function.json" + self.data = {} + self.load() + + def load(self): + """ + 加载文件数据 + """ + try: + with open(self.filename, 'r', encoding="utf-8") as f: + self.data = json.load(f) + except FileNotFoundError: + pass + + def save(self): + """ + 将函数保存至json文件当中 + """ + with open(self.filename, "w", encoding="utf-8") as f: + json.dump(self.data, f) + + def check_function_exit(self, function): + """ + 检查用户输入的函数是否包含用户自定义函数 + """ + for key in self.data.keys(): + if function.find(key) >=0: + return True + return False + + def add_function(self, key, value): + """ + 添加函数 + """ + self.data[key.strip()] = value.strip() + self.save() + + def get_function_by_iter(self, key): + result = key + for dict_key in self.data.keys(): + if result.find(dict_key) >= 0: + value = result.replace(dict_key, self.data[dict_key]) + result = self.replace_values_recursive(value) + return result + + def replace_values_recursive(self, value): + for key in self.data: + if key in value: + replacement = self.data[key] + value = value.replace(key, replacement) + return value diff --git a/x5/image/下部背景.png b/x5/image/下部背景.png new file mode 100644 index 0000000..f610758 Binary files /dev/null and b/x5/image/下部背景.png differ diff --git a/x5/image/下部背景@2x.png b/x5/image/下部背景@2x.png new file mode 100644 index 0000000..4117a49 Binary files /dev/null and b/x5/image/下部背景@2x.png differ diff --git a/x5/image/下部背景@3x.png b/x5/image/下部背景@3x.png new file mode 100644 index 0000000..ec4b13e Binary files /dev/null and b/x5/image/下部背景@3x.png differ diff --git a/x5/image/勾选.png b/x5/image/勾选.png new file mode 100644 index 0000000..1f79713 Binary files /dev/null and b/x5/image/勾选.png differ diff --git a/x5/image/勾选@2x.png b/x5/image/勾选@2x.png new file mode 100644 index 0000000..218acdd Binary files /dev/null and b/x5/image/勾选@2x.png differ diff --git a/x5/image/勾选@3x.png b/x5/image/勾选@3x.png new file mode 100644 index 0000000..7188964 Binary files /dev/null and b/x5/image/勾选@3x.png differ diff --git a/x5/image/勾选选中.png b/x5/image/勾选选中.png new file mode 100644 index 0000000..7924490 Binary files /dev/null and b/x5/image/勾选选中.png differ diff --git a/x5/image/勾选选中@2x.png b/x5/image/勾选选中@2x.png new file mode 100644 index 0000000..43afa0c Binary files /dev/null and b/x5/image/勾选选中@2x.png differ diff --git a/x5/image/勾选选中@3x.png b/x5/image/勾选选中@3x.png new file mode 100644 index 0000000..7851730 Binary files /dev/null and b/x5/image/勾选选中@3x.png differ diff --git a/x5/image/右侧背景.png b/x5/image/右侧背景.png new file mode 100644 index 0000000..98e4b89 Binary files /dev/null and b/x5/image/右侧背景.png differ diff --git a/x5/image/右侧背景@2x.png b/x5/image/右侧背景@2x.png new file mode 100644 index 0000000..d508637 Binary files /dev/null and b/x5/image/右侧背景@2x.png differ diff --git a/x5/image/右侧背景@3x.png b/x5/image/右侧背景@3x.png new file mode 100644 index 0000000..7de0099 Binary files /dev/null and b/x5/image/右侧背景@3x.png differ diff --git a/x5/image/导航背景.jpg b/x5/image/导航背景.jpg new file mode 100644 index 0000000..275a004 Binary files /dev/null and b/x5/image/导航背景.jpg differ diff --git a/x5/image/导航背景@2x.png b/x5/image/导航背景@2x.png new file mode 100644 index 0000000..5122889 Binary files /dev/null and b/x5/image/导航背景@2x.png differ diff --git a/x5/image/导航背景@3x.png b/x5/image/导航背景@3x.png new file mode 100644 index 0000000..981a4b6 Binary files /dev/null and b/x5/image/导航背景@3x.png differ diff --git a/x5/image/文字背景.png b/x5/image/文字背景.png new file mode 100644 index 0000000..83d3134 Binary files /dev/null and b/x5/image/文字背景.png differ diff --git a/x5/image/文字背景2.png b/x5/image/文字背景2.png new file mode 100644 index 0000000..a114b1d Binary files /dev/null and b/x5/image/文字背景2.png differ diff --git a/x5/image/文字背景2@2x.png b/x5/image/文字背景2@2x.png new file mode 100644 index 0000000..c7126bd Binary files /dev/null and b/x5/image/文字背景2@2x.png differ diff --git a/x5/image/文字背景2@3x.png b/x5/image/文字背景2@3x.png new file mode 100644 index 0000000..267e8ef Binary files /dev/null and b/x5/image/文字背景2@3x.png differ diff --git a/x5/image/文字背景@2x.png b/x5/image/文字背景@2x.png new file mode 100644 index 0000000..9f976a6 Binary files /dev/null and b/x5/image/文字背景@2x.png differ diff --git a/x5/image/文字背景@3x.png b/x5/image/文字背景@3x.png new file mode 100644 index 0000000..0c911a8 Binary files /dev/null and b/x5/image/文字背景@3x.png differ diff --git a/x5/image/用户命名并新增基本函数-点击.png b/x5/image/用户命名并新增基本函数-点击.png new file mode 100644 index 0000000..5c4b86b Binary files /dev/null and b/x5/image/用户命名并新增基本函数-点击.png differ diff --git a/x5/image/用户命名并新增基本函数-点击@2x.png b/x5/image/用户命名并新增基本函数-点击@2x.png new file mode 100644 index 0000000..56a9e14 Binary files /dev/null and b/x5/image/用户命名并新增基本函数-点击@2x.png differ diff --git a/x5/image/用户命名并新增基本函数-点击@3x.png b/x5/image/用户命名并新增基本函数-点击@3x.png new file mode 100644 index 0000000..bb3cfa1 Binary files /dev/null and b/x5/image/用户命名并新增基本函数-点击@3x.png differ diff --git a/x5/image/用户命名并新增基本函数.png b/x5/image/用户命名并新增基本函数.png new file mode 100644 index 0000000..1e0f408 Binary files /dev/null and b/x5/image/用户命名并新增基本函数.png differ diff --git a/x5/image/用户命名并新增基本函数@2x.png b/x5/image/用户命名并新增基本函数@2x.png new file mode 100644 index 0000000..453249f Binary files /dev/null and b/x5/image/用户命名并新增基本函数@2x.png differ diff --git a/x5/image/用户命名并新增基本函数@3x.png b/x5/image/用户命名并新增基本函数@3x.png new file mode 100644 index 0000000..1546a58 Binary files /dev/null and b/x5/image/用户命名并新增基本函数@3x.png differ diff --git a/x5/image/背景.jpg b/x5/image/背景.jpg new file mode 100644 index 0000000..6f0af51 Binary files /dev/null and b/x5/image/背景.jpg differ diff --git a/x5/image/背景@2x.jpg b/x5/image/背景@2x.jpg new file mode 100644 index 0000000..365e47c Binary files /dev/null and b/x5/image/背景@2x.jpg differ diff --git a/x5/image/背景@3x.jpg b/x5/image/背景@3x.jpg new file mode 100644 index 0000000..356fb09 Binary files /dev/null and b/x5/image/背景@3x.jpg differ diff --git a/x5/image/象限选择背景.png b/x5/image/象限选择背景.png new file mode 100644 index 0000000..1ca972a Binary files /dev/null and b/x5/image/象限选择背景.png differ diff --git a/x5/image/象限选择背景@2x.png b/x5/image/象限选择背景@2x.png new file mode 100644 index 0000000..c8f5b25 Binary files /dev/null and b/x5/image/象限选择背景@2x.png differ diff --git a/x5/image/象限选择背景@3x.png b/x5/image/象限选择背景@3x.png new file mode 100644 index 0000000..23c9601 Binary files /dev/null and b/x5/image/象限选择背景@3x.png differ diff --git a/x5/image/输入条.png b/x5/image/输入条.png new file mode 100644 index 0000000..adf0782 Binary files /dev/null and b/x5/image/输入条.png differ diff --git a/x5/image/输入条@2x.png b/x5/image/输入条@2x.png new file mode 100644 index 0000000..b2867de Binary files /dev/null and b/x5/image/输入条@2x.png differ diff --git a/x5/image/输入条@3x.png b/x5/image/输入条@3x.png new file mode 100644 index 0000000..abafd68 Binary files /dev/null and b/x5/image/输入条@3x.png differ diff --git a/x5/image/输出-点击.png b/x5/image/输出-点击.png new file mode 100644 index 0000000..0d06be3 Binary files /dev/null and b/x5/image/输出-点击.png differ diff --git a/x5/image/输出-点击@2x.png b/x5/image/输出-点击@2x.png new file mode 100644 index 0000000..26c0c5a Binary files /dev/null and b/x5/image/输出-点击@2x.png differ diff --git a/x5/image/输出-点击@3x.png b/x5/image/输出-点击@3x.png new file mode 100644 index 0000000..dc6f3ad Binary files /dev/null and b/x5/image/输出-点击@3x.png differ diff --git a/x5/image/输出.png b/x5/image/输出.png new file mode 100644 index 0000000..833da41 Binary files /dev/null and b/x5/image/输出.png differ diff --git a/x5/image/输出@2x.png b/x5/image/输出@2x.png new file mode 100644 index 0000000..7f963ee Binary files /dev/null and b/x5/image/输出@2x.png differ diff --git a/x5/image/输出@3x.png b/x5/image/输出@3x.png new file mode 100644 index 0000000..43357e1 Binary files /dev/null and b/x5/image/输出@3x.png differ diff --git a/x5/image/长条输入框.png b/x5/image/长条输入框.png new file mode 100644 index 0000000..13031d2 Binary files /dev/null and b/x5/image/长条输入框.png differ diff --git a/x5/image/长条输入框@2x.png b/x5/image/长条输入框@2x.png new file mode 100644 index 0000000..e53671b Binary files /dev/null and b/x5/image/长条输入框@2x.png differ diff --git a/x5/image/长条输入框@3x.png b/x5/image/长条输入框@3x.png new file mode 100644 index 0000000..006b8b8 Binary files /dev/null and b/x5/image/长条输入框@3x.png differ diff --git a/x5_218/test.py b/x5/test.py similarity index 100% rename from x5_218/test.py rename to x5/test.py diff --git a/x5/test1.py b/x5/test1.py new file mode 100644 index 0000000..c940af0 --- /dev/null +++ b/x5/test1.py @@ -0,0 +1,79 @@ +import tkinter as tk +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg + +def plot_function(func_str, num_points, step, multiplier, x_func): + try: + x_values = np.linspace(x_func[0], x_func[1], num_points) + func = lambda x: eval(func_str) + y_values = func(x_values * multiplier) + + ax.clear() + ax.plot(x_values, y_values, label=f'{func_str} ({x_func[0]} to {x_func[1]})') + ax.legend() + canvas.draw() + except Exception as e: + print(f"Error: {e}") + +def on_update(): + try: + func_str = entry_function.get() + num_points = int(entry_num_points.get()) + step = float(entry_step.get()) + multiplier = float(entry_multiplier.get()) + x_func = [float(entry_x_start.get()), float(entry_x_end.get())] + + plot_function(func_str, num_points, step, multiplier, x_func) + except ValueError: + pass + +# 创建主窗口 +root = tk.Tk() +root.title("Function Plotter") + +# 创建图形区域 +fig, ax = plt.subplots(figsize=(5, 4)) +canvas = FigureCanvasTkAgg(fig, master=root) +canvas_widget = canvas.get_tk_widget() +canvas_widget.grid(row=0, column=1, rowspan=10) + +# 添加控件 +tk.Label(root, text="Function:").grid(row=0, column=0) +entry_function = tk.Entry(root) +entry_function.grid(row=0, column=1) +entry_function.insert(0, "np.sin(x)") + +tk.Label(root, text="Number of Points:").grid(row=1, column=0) +entry_num_points = tk.Entry(root) +entry_num_points.grid(row=1, column=1) +entry_num_points.insert(0, "100") + +tk.Label(root, text="Step Size:").grid(row=2, column=0) +entry_step = tk.Entry(root) +entry_step.grid(row=2, column=1) +entry_step.insert(0, "0.1") + +tk.Label(root, text="Multiplier:").grid(row=3, column=0) +entry_multiplier = tk.Entry(root) +entry_multiplier.grid(row=3, column=1) +entry_multiplier.insert(0, "1.0") + +tk.Label(root, text="X Start:").grid(row=4, column=0) +entry_x_start = tk.Entry(root) +entry_x_start.grid(row=4, column=1) +entry_x_start.insert(0, "-10.0") + +tk.Label(root, text="X End:").grid(row=5, column=0) +entry_x_end = tk.Entry(root) +entry_x_end.grid(row=5, column=1) +entry_x_end.insert(0, "10.0") + +update_button = tk.Button(root, text="Update Plot", command=on_update) +update_button.grid(row=6, column=0, columnspan=2) + +# 初始绘制 +on_update() + +# 运行主循环 +root.mainloop() diff --git a/x5_218/basic.png b/x5_218/basic.png deleted file mode 100644 index c00568c..0000000 Binary files a/x5_218/basic.png and /dev/null differ diff --git a/x5_218/function.json b/x5_218/function.json deleted file mode 100644 index b89b3ef..0000000 --- a/x5_218/function.json +++ /dev/null @@ -1 +0,0 @@ -{"xy": "x*y", "f2": "sin(x)* cos(y)"} \ No newline at end of file diff --git a/函数显示文档.docx b/函数显示文档.docx deleted file mode 100644 index ed52bde..0000000 Binary files a/函数显示文档.docx and /dev/null differ diff --git a/函数绘制.docx b/函数绘制.docx deleted file mode 100644 index 2fed1d0..0000000 Binary files a/函数绘制.docx and /dev/null differ