main
123 6 months ago
parent fd53b8fca5
commit da7605a2e3

@ -11,17 +11,16 @@ class MainPage:
self.create_page() self.create_page()
def create_page(self): 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.home_info_title.pack(pady=20)
# 添加一个按钮用于跳转到家居信息页面 # 添加一个按钮用于跳转到家居信息页面
self.goto_jiaju_button = tk.Button(self.page, text="家居信息", command=self.show_jiaju_info) self.goto_jiaju_button = tk.Button(self.page, text="家居信息", command=self.show_jiaju_info)
self.goto_jiaju_button.pack(pady=10) self.goto_jiaju_button.pack(pady=10)
def show_jiaju_info(self): def show_jiaju_info(self):
# 隐藏当前主页面框架 # 销毁当前页面
self.page.pack_forget() self.page.destroy()
# 显示家居信息页面 # 显示家居信息页面
self.jiaju_page = JiaJuInfoPage(self.root) JiaJuInfoPage(self.root)
class JiaJuInfoPage: class JiaJuInfoPage:
def __init__(self, master): def __init__(self, master):
self.root = master self.root = master
@ -30,9 +29,7 @@ class JiaJuInfoPage:
self.root.geometry('600x400') self.root.geometry('600x400')
JiaJuPage(self.root) JiaJuPage(self.root)
if __name__ == '__main__': if __name__ == '__main__':
root = tk.Tk() root = tk.Tk()
root.title("智能家居系统-主页面")
app = MainPage(root) app = MainPage(root)
root.mainloop() root.mainloop()

@ -1,12 +1,12 @@
import tkinter as tk import tkinter as tk
from tkinter import ttk, messagebox from tkinter import ttk, messagebox
import pymysql import pymysql
from 主页面 import MainPage #from 主页面 import MainPage
class JiaJuPage: class JiaJuPage:
def __init__(self, master): def __init__(self, master):
self.root = master self.root = master
self.root.title("智能家居系统 - 家居信息") self.root.title("智能家居系统 - 家居管理")
self.root.geometry('1000x700') self.root.geometry('1000x700')
self.conn = pymysql.connect(host='localhost', user='root', password='LH20021212', db='智能家居系统', 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.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.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) tk.Button(button_frame, text="返回主页面", command=self.query_all_jiaju).pack(side=tk.LEFT, padx=10)
query_frame = tk.Frame(self.root) query_frame = tk.Frame(self.root)
query_frame.pack(pady=(10, 0)) # 添加一些垂直间隔 query_frame.pack(pady=(10, 0)) # 添加一些垂直间隔
@ -231,18 +231,6 @@ class JiaJuPage:
self.conn.close() self.conn.close()
self.root.destroy() 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__': if __name__ == '__main__':
root = tk.Tk() root = tk.Tk()

@ -8,18 +8,15 @@ import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
class EnvironmentMonitorApp: class EnvironmentMonitorApp:
def __init__(self): def __init__(self, root):
super().__init__() self.root = root
self.title("空调自动调节系统") self.root.title("环境监测数据展示")
self.geometry("800x600") self.setup_ui()
self.data_records = [] # 保存所有监测记录
# 环境监测实例 self.plot_window = None # 初始化图表窗口变量
self.env_monitor = EnvironmentMonitor() self.figure = None # 初始化图表figure变量
self.canvas = None # 初始化图表canvas变量
# 获取初始环境条件 self.axs = None # 初始化子图变量
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秒更新一次数据 self.root.after(5000, self.update_data_and_display) # 每5秒更新一次数据
# 设置matplotlib的字体以支持中文显示 # 设置matplotlib的字体以支持中文显示
@ -103,35 +100,6 @@ class EnvironmentMonitorApp:
ax.grid(True) ax.grid(True)
self.canvas.draw_idle() # 更新图表而不重新绘制整个画布 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(): def main():
root = tk.Tk() root = tk.Tk()

Loading…
Cancel
Save