parent
905b38c36a
commit
a8838866e5
@ -0,0 +1,69 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
import random
|
||||
import time
|
||||
|
||||
# 全局变量
|
||||
comfortable_temperature_range = (20, 24)
|
||||
comfortable_humidity_range = (40, 60)
|
||||
current_temperature = 0
|
||||
current_humidity = 0
|
||||
line_number = 0
|
||||
update_interval = 5000 # 每5秒更新一次
|
||||
root = None
|
||||
treeview = None
|
||||
|
||||
def reset_conditions():
|
||||
global current_temperature, current_humidity
|
||||
current_temperature = random.uniform(-12, 42)
|
||||
current_humidity = random.uniform(0, 100)
|
||||
|
||||
def adjust():
|
||||
global current_temperature, current_humidity
|
||||
reset_conditions()
|
||||
if not comfortable_temperature_range[0] <= current_temperature <= comfortable_temperature_range[1]:
|
||||
current_temperature = random.uniform(*comfortable_temperature_range)
|
||||
if not comfortable_humidity_range[0] <= current_humidity <= comfortable_humidity_range[1]:
|
||||
current_humidity = random.uniform(*comfortable_humidity_range)
|
||||
return current_temperature, current_humidity
|
||||
|
||||
def schedule_update():
|
||||
"""计划下一次更新"""
|
||||
global line_number
|
||||
line_number += 1
|
||||
initial_temp, initial_humidity = current_temperature, current_humidity
|
||||
adjusted_temp, adjusted_humidity = adjust()
|
||||
treeview.insert("", tk.END, values=(line_number,
|
||||
f"{initial_temp:.2f}°C",
|
||||
f"{initial_humidity:.2f}%",
|
||||
f"{adjusted_temp:.2f}°C",
|
||||
f"{adjusted_humidity:.2f}%"))
|
||||
# 安排下一次更新
|
||||
root.after(update_interval, schedule_update)
|
||||
|
||||
def main():
|
||||
global root, treeview
|
||||
root = tk.Tk()
|
||||
root.title("智能家居系统-空调自动调节系统")
|
||||
root.geometry("800x600")
|
||||
|
||||
treeview = ttk.Treeview(root,
|
||||
columns=("编号", "初始温度", "初始湿度", "调节后温度", "调节后湿度"),
|
||||
show="headings")
|
||||
treeview.heading("编号", text="编号")
|
||||
treeview.heading("初始温度", text="初始温度")
|
||||
treeview.heading("初始湿度", text="初始湿度")
|
||||
treeview.heading("调节后温度", text="调节后温度")
|
||||
treeview.heading("调节后湿度", text="调节后湿度")
|
||||
for col in treeview['columns']:
|
||||
treeview.column(col, width=80, anchor=tk.CENTER)
|
||||
treeview.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
|
||||
|
||||
root.rowconfigure(0, weight=1)
|
||||
root.columnconfigure(0, weight=1)
|
||||
|
||||
schedule_update() # 安排首次更新
|
||||
root.mainloop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -0,0 +1,41 @@
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from ZYM import a
|
||||
|
||||
def login_check(root, username_var, password_var):
|
||||
name = username_var.get()
|
||||
pwd = password_var.get()
|
||||
|
||||
if name == '123' and pwd == '123':
|
||||
messagebox.showinfo(title='恭喜', message='登录成功')
|
||||
xiaohui()
|
||||
# MainPage(root) # 如果需要,取消注释此行并确保已正确导入主页面模块
|
||||
else:
|
||||
messagebox.showinfo(title='错误', message='账户或密码错误')
|
||||
|
||||
def main():
|
||||
global root
|
||||
root = tk.Tk()
|
||||
root.title('智能家居系统-登录界面')
|
||||
root.geometry("300x180")
|
||||
|
||||
username_var = tk.StringVar()
|
||||
password_var = tk.StringVar()
|
||||
|
||||
tk.Label(root).grid(row=0, column=0)
|
||||
tk.Label(root, text='账户').grid(row=1,column=0)
|
||||
tk.Entry(root, textvariable=username_var).grid(row=1, column=1)
|
||||
tk.Label(root, text='密码').grid(row=2, column=0)
|
||||
tk.Entry(root, textvariable=password_var).grid(row=2, column=1, pady=10)
|
||||
|
||||
tk.Button(root, text='登录', command=lambda: login_check(root, username_var, password_var)).grid(row=3, column=0, pady=10)
|
||||
tk.Button(root, text='退出', command=root.quit).grid(row=3, column=1, pady=10, sticky=tk.E)
|
||||
|
||||
root.mainloop()
|
||||
|
||||
def xiaohui():
|
||||
root.destroy()
|
||||
a()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,256 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
import pymysql
|
||||
from tkinter import messagebox
|
||||
|
||||
|
||||
|
||||
|
||||
# 初始化数据库连接
|
||||
def init_db_connection():
|
||||
global conn, cursor
|
||||
conn = pymysql.connect(host='localhost', user='root', password='LH20021212', db='智能家居系统', charset='utf8mb4')
|
||||
cursor = conn.cursor()
|
||||
|
||||
|
||||
# 创建主界面
|
||||
def create_main_window():
|
||||
global root, tree, entry_name_query, entry_color_query, entry_brand_query, entry_price_query, entry_production_date_query, button_frame, query_frame
|
||||
|
||||
root = tk.Tk()
|
||||
root.title("智能家居系统-家居信息")
|
||||
root.geometry('1000x700')
|
||||
|
||||
init_db_connection()
|
||||
create_widgets()
|
||||
|
||||
root.protocol("WM_DELETE_WINDOW", close_conn)
|
||||
root.mainloop()
|
||||
|
||||
|
||||
# 创建界面组件
|
||||
def create_widgets():
|
||||
global tree, entry_name_query, entry_color_query, entry_brand_query, entry_price_query, entry_production_date_query, button_frame, query_frame
|
||||
|
||||
# 表格和滚动条
|
||||
frame = tk.Frame(root)
|
||||
frame.pack(fill=tk.BOTH, expand=True)
|
||||
scrollbar_y = tk.Scrollbar(frame, orient=tk.VERTICAL)
|
||||
scrollbar_x = tk.Scrollbar(frame, orient=tk.HORIZONTAL)
|
||||
|
||||
tree = ttk.Treeview(frame, columns=("ID", "名称", "颜色", "品牌", "价格", "生产日期"),
|
||||
yscrollcommand=scrollbar_y.set, xscrollcommand=scrollbar_x.set)
|
||||
tree.heading("#0", text="")
|
||||
tree.heading("ID", text="ID")
|
||||
tree.heading("名称", text="名称")
|
||||
tree.heading("颜色", text="颜色")
|
||||
tree.heading("品牌", text="品牌")
|
||||
tree.heading("价格", text="价格")
|
||||
tree.heading("生产日期", text="生产日期")
|
||||
tree.column("#0", width=0, stretch=tk.NO)
|
||||
tree.column("ID", anchor=tk.CENTER, width=50)
|
||||
tree.column("名称", anchor=tk.CENTER, width=100)
|
||||
tree.column("颜色", anchor=tk.CENTER, width=100)
|
||||
tree.column("品牌", anchor=tk.CENTER, width=100)
|
||||
tree.column("价格", anchor=tk.CENTER, width=100)
|
||||
tree.column("生产日期", anchor=tk.CENTER, width=100)
|
||||
|
||||
tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
||||
scrollbar_y.config(command=tree.yview)
|
||||
scrollbar_y.pack(side=tk.RIGHT, fill=tk.Y)
|
||||
scrollbar_x.config(command=tree.xview)
|
||||
scrollbar_x.pack(side=tk.BOTTOM, fill=tk.X)
|
||||
|
||||
# 按钮区域
|
||||
button_frame = tk.Frame(root)
|
||||
button_frame.pack(pady=10)
|
||||
tk.Button(button_frame, text="添加家居", command=add_jiaju_popup).pack(side=tk.LEFT, padx=10)
|
||||
tk.Button(button_frame, text="删除选中", command=delete_selected_jiaju).pack(side=tk.LEFT, padx=10)
|
||||
tk.Button(button_frame, text="修改选中", command=update_selected_jiaju_popup).pack(side=tk.LEFT, padx=10)
|
||||
tk.Button(button_frame, text="查询所有", command=query_all_jiaju).pack(side=tk.LEFT, padx=10)
|
||||
tk.Button(button_frame, text="返回", command=root.destroy).pack(side=tk.LEFT, padx=10)
|
||||
|
||||
# 查询条件输入框区域
|
||||
query_frame = tk.Frame(root)
|
||||
query_frame.pack(pady=(10, 0))
|
||||
tk.Label(query_frame, text="名称:").pack(side=tk.LEFT)
|
||||
entry_name_query = tk.Entry(query_frame)
|
||||
entry_name_query.pack(side=tk.LEFT, padx=(5, 0))
|
||||
tk.Label(query_frame, text="颜色:").pack(side=tk.LEFT)
|
||||
entry_color_query = tk.Entry(query_frame)
|
||||
entry_color_query.pack(side=tk.LEFT, padx=(5, 0))
|
||||
tk.Label(query_frame, text="品牌:").pack(side=tk.LEFT)
|
||||
entry_brand_query = tk.Entry(query_frame)
|
||||
entry_brand_query.pack(side=tk.LEFT, padx=(5, 0))
|
||||
tk.Label(query_frame, text="价格:").pack(side=tk.LEFT)
|
||||
entry_price_query = tk.Entry(query_frame)
|
||||
entry_price_query.pack(side=tk.LEFT, padx=(5, 0))
|
||||
tk.Label(query_frame, text="生产日期:").pack(side=tk.LEFT)
|
||||
entry_production_date_query = tk.Entry(query_frame)
|
||||
entry_production_date_query.pack(side=tk.LEFT)
|
||||
tk.Button(query_frame, text="查询", command=query_jiaju_condition).pack(side=tk.LEFT, padx=10)
|
||||
|
||||
query_all_jiaju()
|
||||
|
||||
|
||||
# 查询所有家居信息
|
||||
def query_all_jiaju():
|
||||
tree.delete(*tree.get_children())
|
||||
cursor.execute("SELECT * FROM jia_ju")
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
tree.insert('', tk.END, values=row)
|
||||
|
||||
|
||||
# 添加家居弹窗
|
||||
def add_jiaju_popup():
|
||||
def submit_add():
|
||||
name = entry_name.get()
|
||||
color = entry_color.get()
|
||||
brand = entry_brand.get()
|
||||
price = entry_price.get()
|
||||
production_date = entry_production_date.get()
|
||||
sql = f"INSERT INTO jia_ju(name, color, brand, price, production_date) VALUES ('{name}', '{color}', '{brand}', {price}, '{production_date}')"
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
messagebox.showinfo("成功", "家居信息录入成功!")
|
||||
add_window.destroy()
|
||||
query_all_jiaju()
|
||||
except Exception as e:
|
||||
messagebox.showerror("错误", f"录入失败: {e}")
|
||||
|
||||
add_window = tk.Toplevel(root)
|
||||
add_window.title("录入家居信息")
|
||||
tk.Label(add_window, text="名称:").pack()
|
||||
entry_name = tk.Entry(add_window)
|
||||
entry_name.pack()
|
||||
tk.Label(add_window, text="颜色:").pack()
|
||||
entry_color = tk.Entry(add_window)
|
||||
entry_color.pack()
|
||||
tk.Label(add_window, text="品牌:").pack()
|
||||
entry_brand = tk.Entry(add_window)
|
||||
entry_brand.pack()
|
||||
tk.Label(add_window, text="价格:").pack()
|
||||
entry_price = tk.Entry(add_window)
|
||||
entry_price.pack()
|
||||
tk.Label(add_window, text="生产日期:").pack()
|
||||
entry_production_date = tk.Entry(add_window)
|
||||
entry_production_date.pack()
|
||||
tk.Button(add_window, text="提交", command=submit_add).pack()
|
||||
|
||||
# 删除选中家居
|
||||
def delete_selected_jiaju(self):
|
||||
selected_items = self.tree.selection()
|
||||
if not selected_items:
|
||||
messagebox.showwarning("警告", "请先选择要删除的家居项!")
|
||||
return
|
||||
for item in selected_items:
|
||||
item_id = self.tree.item(item)['values'][0]
|
||||
sql = f"DELETE FROM jia_ju WHERE id={item_id}"
|
||||
try:
|
||||
self.cursor.execute(sql)
|
||||
self.conn.commit()
|
||||
except Exception as e:
|
||||
messagebox.showerror("错误", f"删除失败: {e}")
|
||||
self.conn.rollback()
|
||||
return
|
||||
messagebox.showinfo("成功", "选中的家居信息已删除!")
|
||||
self.query_all_jiaju() # 刷新列表
|
||||
|
||||
# 修改选中家居弹窗
|
||||
def update_selected_jiaju_popup():
|
||||
selected_items = tree.selection()
|
||||
if not selected_items:
|
||||
messagebox.showwarning("警告", "请先选择要修改的家居项!")
|
||||
return
|
||||
|
||||
item = selected_items[0]
|
||||
item_values = tree.item(item)['values']
|
||||
item_id = item_values[0]
|
||||
|
||||
def submit_update():
|
||||
name = entry_name.get()
|
||||
color = entry_color.get()
|
||||
brand = entry_brand.get()
|
||||
price = entry_price.get()
|
||||
production_date = entry_production_date.get()
|
||||
sql = f"UPDATE jia_ju SET name='{name}', color='{color}', brand='{brand}', price={price}, production_date='{production_date}' WHERE id={item_id}"
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
messagebox.showinfo("成功", "家居信息已更新!")
|
||||
update_window.destroy()
|
||||
query_all_jiaju()
|
||||
except Exception as e:
|
||||
messagebox.showerror("错误", f"更新失败: {e}")
|
||||
|
||||
update_window = tk.Toplevel(root)
|
||||
update_window.title("修改家居信息")
|
||||
tk.Label(update_window, text="名称:").pack()
|
||||
entry_name = tk.Entry(update_window)
|
||||
entry_name.insert(tk.END, item_values[1])
|
||||
entry_name.pack()
|
||||
tk.Label(update_window, text="颜色:").pack()
|
||||
entry_color = tk.Entry(update_window)
|
||||
entry_color.insert(tk.END, item_values[2])
|
||||
entry_color.pack()
|
||||
tk.Label(update_window, text="品牌:").pack()
|
||||
entry_brand = tk.Entry(update_window)
|
||||
entry_brand.insert(tk.END, item_values[3])
|
||||
entry_brand.pack()
|
||||
tk.Label(update_window, text="价格:").pack()
|
||||
entry_price = tk.Entry(update_window)
|
||||
entry_price.insert(tk.END, item_values[4])
|
||||
entry_price.pack()
|
||||
tk.Label(update_window, text="生产日期:").pack()
|
||||
entry_production_date = tk.Entry(update_window)
|
||||
entry_production_date.insert(tk.END, item_values[5])
|
||||
entry_production_date.pack()
|
||||
tk.Button(update_window, text="提交修改", command=submit_update).pack()
|
||||
|
||||
# 条件查询家居
|
||||
def query_jiaju_condition():
|
||||
name_cond = entry_name_query.get().strip()
|
||||
color_cond = entry_color_query.get().strip()
|
||||
brand_cond = entry_brand_query.get().strip()
|
||||
price_cond = entry_price_query.get().strip()
|
||||
production_date_cond = entry_production_date_query.get().strip()
|
||||
|
||||
conditions = []
|
||||
if name_cond:
|
||||
conditions.append(f"name LIKE '%{name_cond}%'")
|
||||
if color_cond:
|
||||
conditions.append(f"color LIKE '%{color_cond}%'")
|
||||
if brand_cond:
|
||||
conditions.append(f"brand LIKE '%{brand_cond}%'")
|
||||
if price_cond.isdigit():
|
||||
conditions.append(f"price = {price_cond}")
|
||||
if production_date_cond:
|
||||
conditions.append(f"production_date = '{production_date_cond}'")
|
||||
|
||||
where_clause = ' AND '.join(conditions) if conditions else '1=1'
|
||||
sql = f"SELECT * FROM jia_ju WHERE {where_clause}"
|
||||
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
rows = cursor.fetchall()
|
||||
tree.delete(*tree.get_children())
|
||||
for row in rows:
|
||||
tree.insert('', tk.END, values=row)
|
||||
except Exception as e:
|
||||
messagebox.showerror("错误", f"查询失败: {e}")
|
||||
conn.rollback()
|
||||
|
||||
# 关闭数据库连接
|
||||
def close_conn():
|
||||
cursor.close()
|
||||
conn.close()
|
||||
root.destroy()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
create_main_window()
|
@ -0,0 +1,69 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
import random
|
||||
import time
|
||||
|
||||
# 全局变量
|
||||
comfortable_temperature_range = (20, 24)
|
||||
comfortable_humidity_range = (40, 60)
|
||||
current_temperature = 0
|
||||
current_humidity = 0
|
||||
line_number = 0
|
||||
update_interval = 5000 # 每5秒更新一次
|
||||
root = None
|
||||
treeview = None
|
||||
|
||||
def reset_conditions():
|
||||
global current_temperature, current_humidity
|
||||
current_temperature = random.uniform(-12, 42)
|
||||
current_humidity = random.uniform(0, 100)
|
||||
|
||||
def adjust():
|
||||
global current_temperature, current_humidity
|
||||
reset_conditions()
|
||||
if not comfortable_temperature_range[0] <= current_temperature <= comfortable_temperature_range[1]:
|
||||
current_temperature = random.uniform(*comfortable_temperature_range)
|
||||
if not comfortable_humidity_range[0] <= current_humidity <= comfortable_humidity_range[1]:
|
||||
current_humidity = random.uniform(*comfortable_humidity_range)
|
||||
return current_temperature, current_humidity
|
||||
|
||||
def schedule_update():
|
||||
"""计划下一次更新"""
|
||||
global line_number
|
||||
line_number += 1
|
||||
initial_temp, initial_humidity = current_temperature, current_humidity
|
||||
adjusted_temp, adjusted_humidity = adjust()
|
||||
treeview.insert("", tk.END, values=(line_number,
|
||||
f"{initial_temp:.2f}°C",
|
||||
f"{initial_humidity:.2f}%",
|
||||
f"{adjusted_temp:.2f}°C",
|
||||
f"{adjusted_humidity:.2f}%"))
|
||||
# 安排下一次更新
|
||||
root.after(update_interval, schedule_update)
|
||||
|
||||
def main():
|
||||
global root, treeview
|
||||
root = tk.Tk()
|
||||
root.title("智能家居系统-空调自动调节系统")
|
||||
root.geometry("800x600")
|
||||
|
||||
treeview = ttk.Treeview(root,
|
||||
columns=("编号", "初始温度", "初始湿度", "调节后温度", "调节后湿度"),
|
||||
show="headings")
|
||||
treeview.heading("编号", text="编号")
|
||||
treeview.heading("初始温度", text="初始温度")
|
||||
treeview.heading("初始湿度", text="初始湿度")
|
||||
treeview.heading("调节后温度", text="调节后温度")
|
||||
treeview.heading("调节后湿度", text="调节后湿度")
|
||||
for col in treeview['columns']:
|
||||
treeview.column(col, width=80, anchor=tk.CENTER)
|
||||
treeview.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
|
||||
|
||||
root.rowconfigure(0, weight=1)
|
||||
root.columnconfigure(0, weight=1)
|
||||
|
||||
schedule_update() # 安排首次更新
|
||||
root.mainloop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
17.5219813233319,10.705621045530922
|
Binary file not shown.
Loading…
Reference in new issue