diff --git a/智能家居系统/__pycache__/主页面.cpython-311.pyc b/智能家居系统/__pycache__/主页面.cpython-311.pyc index 3034c64..3f75258 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 d006a5b..72f7cdb 100644 Binary files a/智能家居系统/__pycache__/家居信息.cpython-311.pyc and b/智能家居系统/__pycache__/家居信息.cpython-311.pyc differ diff --git a/智能家居系统/家居信息.py b/智能家居系统/家居信息.py index a4c829c..8bb3a3b 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.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) query_frame = tk.Frame(self.root) query_frame.pack(pady=(10, 0)) # 添加一些垂直间隔 @@ -231,6 +231,18 @@ 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 c64b075..1cf9727 100644 --- a/智能家居系统/环境监测.py +++ b/智能家居系统/环境监测.py @@ -7,17 +7,19 @@ import time import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg - class EnvironmentMonitorApp: - 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 # 初始化子图变量 + 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) self.root.after(5000, self.update_data_and_display) # 每5秒更新一次数据 # 设置matplotlib的字体以支持中文显示 @@ -42,8 +44,8 @@ class EnvironmentMonitorApp: def simulate_data(self): - self.temperature = random.uniform(-15, 40)#20-24 - self.humidity = random.uniform(0, 100)#40-60 + self.temperature = random.uniform(-15, 45)#18-25 + self.humidity = random.uniform(0, 100)#30-60 self.light_intensity = random.randint(100, 1000)#300-500 self.data_records.append({ "序号": len(self.data_records) + 1, @@ -101,15 +103,36 @@ class EnvironmentMonitorApp: ax.grid(True) self.canvas.draw_idle() # 更新图表而不重新绘制整个画布 +# 环境监测模拟 class EnvironmentMonitor: def __init__(self): - # 这里仅作为示例,实际应用中可能从传感器读取 - self.temperature = random.uniform(16, 30) - self.humidity = random.uniform(0, 100) + 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() app = EnvironmentMonitorApp(root) diff --git a/智能家居系统/空调调节.py b/智能家居系统/空调调节.py index 65f852f..ff3ff6a 100644 --- a/智能家居系统/空调调节.py +++ b/智能家居系统/空调调节.py @@ -3,31 +3,8 @@ from tkinter import ttk import random import time -from 环境监测 import EnvironmentMonitor - - -def generate_initial_conditions(): - """ - 生成初始的温度和湿度条件,模拟从环境监测系统获取数据。 - """ - initial_temperature = random.uniform(16, 30) # 模拟从环境监测获得的温度 - initial_humidity = random.uniform(0, 100) # 模拟从环境监测获得的湿度 - return initial_temperature, initial_humidity class AirConditioner: - def __init__(self, initial_temperature=None, initial_humidity=None): - if initial_temperature is not None: - self.current_temperature = initial_temperature - else: - self.current_temperature = random.uniform(16, 30) - - if initial_humidity is not None: - self.current_humidity = initial_humidity - else: - self.current_humidity = random.uniform(0, 100) - - def __init__(self, initial_temperature, initial_humidity): - self.current_temperature = initial_temperature - self.current_humidity = initial_humidity + def __init__(self): self.current_temperature = random.uniform(16, 30) self.current_humidity = random.uniform(0, 100) self.min_temperature = 16 @@ -85,17 +62,6 @@ class ACApp(tk.Tk): self.title("空调自动调节系统") self.geometry("800x600") # 调整窗口大小以适应内容 - # 从环境监测模拟获取初始温度和湿度 - self.initial_temperature, self.initial_humidity = generate_initial_conditions() - - # 初始化空调对象,传入初始温度和湿度 - self.aircon = AirConditioner( - initial_temperature=self.initial_temperature, - initial_humidity=self.initial_humidity - ) - - - # 创建Treeview表格 self.treeview = ttk.Treeview(self, columns=("编号", "初始温度", "初始湿度", "调节后温度", "调节后湿度"), show="headings") @@ -164,8 +130,5 @@ class ACApp(tk.Tk): if __name__ == "__main__": - env_monitor = EnvironmentMonitor() # 创建环境监测实例 - current_temp, current_humidity = env_monitor.get_current_conditions() # 获取当前环境温湿度 - - app = ACApp(current_temp, current_humidity) # 传入实际的温湿度值初始化ACApp + app = ACApp() app.mainloop() \ No newline at end of file