diff --git a/integration/Window.py b/integration/Window.py index 15d9931f69b374b09f772dd2a8748fe8c52ae8f1..3d78ccd97193d534fbce7068bee1fe8169e671c1 100644 --- a/integration/Window.py +++ b/integration/Window.py @@ -2,6 +2,7 @@ import socket import threading import time import tkinter as tk +from PIL import Image, ImageTk from tkinter import font as tkFont from matplotlib.figure import Figure from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg @@ -573,10 +574,24 @@ class WelcomeWindow: self.root.rowconfigure(0, weight=1) self.root.rowconfigure(1, weight=1) - self.frame1 = tk.Frame(self.root, borderwidth=1, relief="solid", width=self.width, height=self.height) - self.frame1.grid(row=0, column=0, columnspan=2, rowspan=2, sticky="nsew") - self.button1 = tk.Button(self.frame1, text="Start", command=self.startButton) - self.button1.place(relx=0.5, rely=0.8, anchor='center') + try: + self.bg_image = Image.open("backGrond.jpg") + print("Image loaded successfully") + self.bg_image = self.bg_image.resize((self.width, self.height), Image.Resampling.LANCZOS) + self.bg_photo = ImageTk.PhotoImage(self.bg_image) + + self.bg_label = tk.Label(self.root, image=self.bg_photo) + self.bg_label.place(x=0, y=0, relwidth=1, relheight=1) + except Exception as e: + print(f"Error loading image: {e}") + + #self.frame1 = tk.Frame(self.root, borderwidth=1, relief="solid", width=self.width, height=self.height) + #self.frame1.grid(row=0, column=0, columnspan=2, rowspan=2, sticky="nsew") + #self.button1 = tk.Button(self.frame1, text="Start", command=self.startButton) + #self.button1.place(relx=0.5, rely=0.8, anchor='center') + self.button1 = tk.Button(self.root, text="Start", command=self.startButton,width=18, + height=2, font=("Helvetica", 15)) + self.button1.place(relx=0.8, rely=0.8, anchor='center') # Position the button relative to the root window def startButton(self): self.root.destroy() # Close the welcome window @@ -765,20 +780,27 @@ class trainingInterface: ''' Train Data ''' + def trainData(self): - if (self.savedDataClose !=[])and (self.savedDataOpen!=[]): - vertical_line = Algorithm(self.savedDataClose, self.savedDataOpen) - print(f"垂直线方程: y = {vertical_line.a}x + {vertical_line.b}") - - with open('trained.txt', 'w') as file: - file.write(f"{vertical_line.a}\n") - file.write(f"{vertical_line.b}\n") - - test_points = [[2, 5], [3, 3], [4, 1]] - for point in test_points: - position = vertical_line.predict(point) - print(f"点 {point} 在垂直线的 {'左侧' if position == -1 else '右侧' if position == 1 else '上面/下面'}") - return vertical_line + # 删除文件 'trained.txt',如果存在 + if os.path.exists('trained.txt'): + os.remove('trained.txt') + + if (self.savedDataClose != []) and (self.savedDataOpen != []): + vertical_line = Algorithm(self.savedDataClose, self.savedDataOpen) + print(f"垂直线方程: y = {vertical_line.a}x + {vertical_line.b}") + + # 创建新的 'trained.txt' 文件并写入内容 + with open('trained.txt', 'w') as file: + file.write(f"{vertical_line.a}\n") + file.write(f"{vertical_line.b}\n") + + test_points = [[2, 5], [3, 3], [4, 1]] + for point in test_points: + position = vertical_line.predict(point) + print(f"点 {point} 在垂直线的 {'左侧' if position == -1 else '右侧' if position == 1 else '上面/下面'}") + + return vertical_line def _decode(self, serial_data): serial_string = serial_data.decode(errors="ignore") diff --git a/integration/backGrond.jpg b/integration/backGrond.jpg new file mode 100644 index 0000000000000000000000000000000000000000..513b7da40dadd724722df759a07d2dddc7bc561b Binary files /dev/null and b/integration/backGrond.jpg differ diff --git a/integration/trained-example.txt b/integration/trained-example.txt new file mode 100644 index 0000000000000000000000000000000000000000..86a5cf890b659fb481410dd616dc94526bbe6091 --- /dev/null +++ b/integration/trained-example.txt @@ -0,0 +1,2 @@ +-0.017490801134218237 +16.477880343919935 diff --git a/integration/trained.txt b/integration/trained.txt new file mode 100644 index 0000000000000000000000000000000000000000..9ffd8f384f9a365e8152d3eca100e225db56b725 --- /dev/null +++ b/integration/trained.txt @@ -0,0 +1,2 @@ +-4.308032026124673 +197.37737171243225