美化下面界面:import tkinter as tk window = tk.Tk() window.title("灯泡控制") light_labels = [] for i in range(6): label = tk.Label(window, text="灯泡{}".format(i+1), bg="gray", width=10) label.grid(row=i, column=0) light_labels.append(label) def update_lights(light_states): for i, state in enumerate(light_states): if state == 1: light_labels[i].configure(bg="green") else: light_labels[i].configure(bg="gray") def backend_output(): # 在这里调用后端代码,获取灯泡状态 light_states = [0, 1, 0, 1, 1, 0] # 示例,替换为实际的后端输出 update_lights(light_states) button = tk.Button(window, text="更新灯泡状态", command=backend_output) button.grid(row=6, column=0) window.mainloop()
时间: 2024-04-08 14:32:49 浏览: 43
tcl.rar_.tcl_tcl_tcl tk_tcl/tk_tcl_tk
import tkinter as tk
window = tk.Tk()
window.title("灯泡控制")
light_labels = []
for i in range(6):
label = tk.Label(window, text="灯泡{}".format(i+1), bg="gray", width=10)
label.grid(row=i, column=0)
light_labels.append(label)
def update_lights(light_states):
for i, state in enumerate(light_states):
if state == 1:
light_labels[i].configure(bg="green")
else:
light_labels[i].configure(bg="gray")
def backend_output():
# 在这里调用后端代码,获取灯泡状态
light_states = [0, 1, 0, 1, 1, 0] # 示例,替换为实际的后端输出
update_lights(light_states)
button = tk.Button(window, text="更新灯泡状态", command=backend_output)
button.grid(row=6, column=0)
window.mainloop()
阅读全文