From fd53b8fca52c0a6a7e85a6895b298e5cbb4a7188 Mon Sep 17 00:00:00 2001 From: 123 <2070873540@qq.com> Date: Sat, 1 Jun 2024 22:48:54 +0800 Subject: [PATCH] 6 commit --- .../__pycache__/主页面.cpython-311.pyc | Bin 2970 -> 2995 bytes .../__pycache__/家居信息.cpython-311.pyc | Bin 20085 -> 20641 bytes 智能家居系统/家居信息.py | 18 +++++- 智能家居系统/环境监测.py | 53 +++++++++++++----- 智能家居系统/空调调节.py | 41 +------------- 5 files changed, 55 insertions(+), 57 deletions(-) diff --git a/智能家居系统/__pycache__/主页面.cpython-311.pyc b/智能家居系统/__pycache__/主页面.cpython-311.pyc index 3034c64eb9bdfc23d7f2094109005903bbee04e5..3f7525816aa2c14d7dce75805984014132d3689b 100644 GIT binary patch delta 345 zcmbOwzFC}aIWI340}%W)icV8t-N+})#+Wr(hb`8Bmn{`48aVVjDDJ|MZ7@X zE$)KEvQXpfaChIV}PoBsrud4;*7J+Oj(g6{oAVL>Jh=B-@8;UewgyiJA zoYNS!CYNw2OQEXy#bJ}1pHiBWYFA`Fc_WvzhA<=037Eu3kk}W5gvMkUZgobX$u8Vs E0B8PEtpET3 delta 256 zcmdliK1-Z$IWI340}xDCib(s*vXM`gjWJ=e4qNQx{~T<>nv8y$EJeIP>09h6sl_El z`IVD5u!&5*z@~313=}Qa0TK-i4>)*wIInX^UgD6v$RT}&L;3=T^ivMe2`N)DFLEec z;ZV2$Lz9i!n~q9l?@Fp!jns+1BSCMG1FbEjKqFy7ty=G=47 zeVudeo%@H#&=7Hc;c(alD5XoczSgsFzcZUm>@O-Tl?B-tFb6Gl79tpgwSsKgBgp3C z20=Ipk6!AmiYQx}d7Z8|2nuORV3lc^IdwLuSQXoG0_N~cncEc`tF&a9t%|+L!5Wri zn-trilM&CHL?XzfhChkqx?-J$s6Bj7te+}%~IoUF9%5$f!+twxaS zu^u85%jo%`v7TY}ry)%2v8~3%Hj>9q*%db7*v`6>?X1?hjTEq+C24(E!k%(`e~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T36+5m~H3SNGE$sc??c!q^}G_=KCO-Cz@kup{!~T*br?ctBa!+JvWx4xAD2Z4lk5cTpl*sp5%@QI^08P1>R5GU@>}12pJRPUs_a5}qXVBG8>~hnEOrgyV!0 zgp-691foKO+{_j&7m80pQ{P~ZSM%cXD( zf8bdJ_qJ6<{#67tQVoC;!u*N07^^l4Z7#>1?#$EoZ?$Ni{wS+@x zM4<#>x9#dDm#)3~vE95zhW)c>F8Yv`g=q;V>)-TAe4>vyB}NL^RTIMnVGaRQEY?scuFuL$-N3Wx%Y z^tJPoH!i>R)5Q;Nd^p(}l`G*XG9N^kEqv@*sQmgVuP%AU5v^upMzjOZOmJv@4%H47?FX^sZw-jZlB+xv=PQoq%l?@Vv zcM;P9&?)NAK1 mkumnIP%+ED>ycM3xCcarq5U_1vGl**ZSCS4w(fG$Eq?>EAi=`` 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