diff --git a/智能家居系统/__pycache__/主页面.cpython-311.pyc b/智能家居系统/__pycache__/主页面.cpython-311.pyc index 3f75258..c8c6207 100644 Binary files a/智能家居系统/__pycache__/主页面.cpython-311.pyc and b/智能家居系统/__pycache__/主页面.cpython-311.pyc differ diff --git a/智能家居系统/__pycache__/家居信息.cpython-311.pyc b/智能家居系统/__pycache__/家居信息.cpython-311.pyc index 72f7cdb..48198c2 100644 Binary files a/智能家居系统/__pycache__/家居信息.cpython-311.pyc and b/智能家居系统/__pycache__/家居信息.cpython-311.pyc differ diff --git a/智能家居系统/主页面.py b/智能家居系统/主页面.py index 4cfe3fe..2db2d56 100644 --- a/智能家居系统/主页面.py +++ b/智能家居系统/主页面.py @@ -11,17 +11,16 @@ class MainPage: self.create_page() def create_page(self): # 创建一个标签用于展示简单的家居信息标题 - self.home_info_title = tk.Label(self.page, text="功能区", font=("Helvetica", 16)) + self.home_info_title = tk.Label(self.page, text="主页面区", font=("Helvetica", 16)) self.home_info_title.pack(pady=20) # 添加一个按钮用于跳转到家居信息页面 self.goto_jiaju_button = tk.Button(self.page, text="家居信息", command=self.show_jiaju_info) self.goto_jiaju_button.pack(pady=10) - def show_jiaju_info(self): - # 隐藏当前主页面框架 - self.page.pack_forget() + # 销毁当前页面 + self.page.destroy() # 显示家居信息页面 - self.jiaju_page = JiaJuInfoPage(self.root) + JiaJuInfoPage(self.root) class JiaJuInfoPage: def __init__(self, master): self.root = master @@ -30,9 +29,7 @@ class JiaJuInfoPage: self.root.geometry('600x400') JiaJuPage(self.root) - if __name__ == '__main__': root = tk.Tk() - root.title("智能家居系统-主页面") app = MainPage(root) root.mainloop() \ No newline at end of file diff --git a/智能家居系统/家居信息.py b/智能家居系统/家居信息.py index 8bb3a3b..a4c829c 100644 --- a/智能家居系统/家居信息.py +++ b/智能家居系统/家居信息.py @@ -1,12 +1,12 @@ import tkinter as tk from tkinter import ttk, messagebox import pymysql -from 主页面 import MainPage +#from 主页面 import MainPage class JiaJuPage: def __init__(self, master): self.root = master - self.root.title("智能家居系统 - 家居信息") + self.root.title("智能家居系统 - 家居管理") self.root.geometry('1000x700') self.conn = pymysql.connect(host='localhost', user='root', password='LH20021212', db='智能家居系统', @@ -54,7 +54,7 @@ class JiaJuPage: tk.Button(button_frame, text="删除选中", command=self.delete_selected_jiaju).pack(side=tk.LEFT, padx=10) tk.Button(button_frame, text="修改选中", command=self.update_selected_jiaju_popup).pack(side=tk.LEFT, padx=10) tk.Button(button_frame, text="查询所有", command=self.query_all_jiaju).pack(side=tk.LEFT, padx=10) - tk.Button(button_frame, text="返回主页面", command=self.return_to_MainPage).pack(side=tk.LEFT, padx=10) + tk.Button(button_frame, text="返回主页面", command=self.query_all_jiaju).pack(side=tk.LEFT, padx=10) query_frame = tk.Frame(self.root) query_frame.pack(pady=(10, 0)) # 添加一些垂直间隔 @@ -231,18 +231,6 @@ class JiaJuPage: self.conn.close() self.root.destroy() - def return_to_main_page(self): - # 关闭当前家居信息页面的数据库连接(如果之前没有在其他地方关闭) - self.close_conn() - - # 销毁当前家居信息窗口 - self.root.destroy() - - # 实例化并运行主页面(这将覆盖当前窗口) - root = tk.Tk() - app = MainPage(root) - root.mainloop() - if __name__ == '__main__': root = tk.Tk() diff --git a/智能家居系统/环境监测.py b/智能家居系统/环境监测.py index 1cf9727..386b941 100644 --- a/智能家居系统/环境监测.py +++ b/智能家居系统/环境监测.py @@ -8,18 +8,15 @@ import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg class EnvironmentMonitorApp: - def __init__(self): - super().__init__() - self.title("空调自动调节系统") - self.geometry("800x600") - - # 环境监测实例 - self.env_monitor = EnvironmentMonitor() - - # 获取初始环境条件 - initial_temp, initial_humid = self.env_monitor.get_current_conditions() - # 空调调节实例 - self.aircon = AirConditioner(initial_temp, initial_humid) + def __init__(self, root): + self.root = root + self.root.title("环境监测数据展示") + self.setup_ui() + self.data_records = [] # 保存所有监测记录 + self.plot_window = None # 初始化图表窗口变量 + self.figure = None # 初始化图表figure变量 + self.canvas = None # 初始化图表canvas变量 + self.axs = None # 初始化子图变量 self.root.after(5000, self.update_data_and_display) # 每5秒更新一次数据 # 设置matplotlib的字体以支持中文显示 @@ -103,35 +100,6 @@ class EnvironmentMonitorApp: ax.grid(True) self.canvas.draw_idle() # 更新图表而不重新绘制整个画布 -# 环境监测模拟 -class EnvironmentMonitor: - def __init__(self): - self.temperature = random.uniform(18, 25) # 初始温度范围调整为更合理的室温范围 - self.humidity = random.uniform(30, 60) # 初始湿度范围调整为常见室内湿度范围 - - def get_current_conditions(self): - return self.temperature, self.humidity - -# 空调调节模拟 -class AirConditioner: - def __init__(self, initial_temperature, initial_humidity): - self.current_temperature = initial_temperature - self.current_humidity = initial_humidity - self.min_temperature = 16 - self.max_temperature = 30 - self.min_humidity = 0 - self.max_humidity = 100 - self.comfortable_temperature_range = (20, 24) - self.comfortable_humidity_range = (40, 60) - - def adjust(self): - if not self.comfortable_temperature_range[0] <= self.current_temperature <= self.comfortable_temperature_range[1]: - self.current_temperature += 1 if self.current_temperature < self.comfortable_temperature_range[0] else -1 - if not self.comfortable_humidity_range[0] <= self.current_humidity <= self.comfortable_humidity_range[1]: - self.current_humidity += 5 if self.current_humidity < self.comfortable_humidity_range[0] else -5 - - def display_status(self): - print(f"当前温度: {self.current_temperature:.1f}°C, 当前湿度: {self.current_humidity:.1f}%") def main(): root = tk.Tk()