文件名:dcs_tkinter.py
import tkinter as tk
from tkinter import messagebox
import redis
# 连接Redis
r = redis.Redis(host='localhost', port=6379, db=0)
def update_redis_and_display():
try:
# 从输入框获取值
positive_layers = int(entry_positive.get())
negative_layers = int(entry_negative.get())
# 更新Redis
r.set('D6060', positive_layers)
r.set('D6062', negative_layers)
# 更新界面显示
label_result.config(text=f"正极层数: {positive_layers}, 负极层数: {negative_layers}")
messagebox.showinfo("成功", "正负极层数已更新")
except ValueError:
messagebox.showerror("错误", "请输入有效的整数")
# 创建主窗口
root = tk.Tk()
root.title("正负极层数更新器")
root.geometry("300x400")
# 创建输入框和标签
label_positive = tk.Label(root, text="正极层数")
label_positive.pack(pady=(10, 0))
entry_positive = tk.Entry(root)
entry_positive.pack()
label_negative = tk.Label(root, text="负极层数")
label_negative.pack(pady=(10, 0))
entry_negative = tk.Entry(root)
entry_negative.pack()
# 创建修改按钮
button_update = tk.Button(root, text="修改正负极层数值", command=update_redis_and_display)
button_update.pack(pady=(20, 0))
# 创建显示结果的标签
label_result = tk.Label(root, text="")
label_result.pack(pady=(20, 0))
# 运行主循环
root.mainloop()
编译:
pyinstaller --onefile --windowed dcs_tkinter.py
效果图: