我正在从事房屋安全项目,但我想在同一时间运行一项功能。当我在下面的代码中打开AC的安全性,然后切换到MS时,如果我在sec_MS(1)中有一个循环,我希望AC保持运行,但不影响MS的程序。如果您不理解,请查看以下代码:
##Library importing:
import Tkinter as tk
import tkFont
import tkSimpleDialog
##Variables:
btnchange = "Off"
btn2change = "AC"
AC_Status = "Off"
MS_Status = "Off"
##Making window
root = tk.Tk()
root.title("Home Security")
root.geometry("450x450")
##Homesecurity Label:
label = tk.Label(root, text="\n\n\nHome Security:")
label.config(font=("Courier", 44))
label.pack()
##Trn MC-On/Off func:
def sec_MS(OO1):
if (OO1 == 1):
print("MS Security On...")
btnchange = "On"
if (OO1 == 0):
print("MS Security Off...")
btnchange = "Off"
##Trn AHC-On/Off func:
def sec_AC(OO2):
if (OO2 == 1):
print("AC Security On...")
btnchange = "On"
if (OO2 == 0):
print("AC Security Off...")
btnchange = "Off"
##Trn off all scrty whn runned:
sec_AC(0)
sec_MS(0)
##def btn-cmd = trn scrty on/off:
def secon_off():
if btn["text"] == "Off":
btnchange = "On"
if btn2["text"] == "AC":
sec_AC(1)
if btn2["text"] == "MS":
sec_MS(1)
if btn["text"] == "On":
btnchange = "Off"
if btn2["text"] == "AC":
sec_AC(0)
if btn2["text"] == "MS":
sec_MS(0)
btn["text"] = btnchange
##def btn-cmd = swtch scrty type:
def WSEC():
global AC_Status
global MS_Status
if btn2["text"] == "AC":
AC_Status = btn["text"]
btn["text"] = MS_Status
btn2change = "MS"
if btn["text"] == "On":
sec_MS(1)
if btn["text"] == "Off":
sec_MS(0)
if btn2["text"] == "MS":
MS_Status = btn["text"]
btn["text"] = AC_Status
btn2change = "AC"
if btn["text"] == "Off":
sec_AC(0)
if btn["text"] == "On":
sec_AC(1)
btn2["text"] = btn2change
##Button/BtnFont:
helv23 = tkFont.Font(family='Arial', size=23)
btn2 = tk.Button(root, text="AC", width=27, command=WSEC)
btn = tk.Button(root, text="Off", width=27, command=secon_off)
btn2["font"] = helv23
btn["font"] = helv23
btn2.pack()
btn.pack()
##Run the mainloop:
root.mainloop()