在 if/else 拆分中传递 askyesno
Passing askyesno across an if/else split
查看此代码片段:
exclude = ["BURSAR", "SHOP"]
if any ((name in machineName for name in exclude)):
question = askyesno('Warning', "That machine is on the exclude list. Are you sure you wish to continue?")
if question == False:
showinfo("No", "Cancelling action.")
else:
showinfo("Yes", "Continuing with Delprof...")
else:
reply = subprocess.Popen(Command ...)
'machineName' 从上方传入,然后我需要它询问 machineName 是否在排除列表中,但如果人们说是,则给他们选项以继续执行命令。
如何通过 else: 和 运行 命令传递代码?
谢谢,克里斯。
如果您将最后一个 else 替换为 if question:
,如果 question
为 True
,则其后的代码将仅 运行。如果你这样做,你应该在第一个 if.
之前初始化 question = True
exclude = ["BURSAR", "SHOP"]
question = True
if any ((name in machineName for name in exclude)):
question = askyesno('Warning', "That machine is on the exclude list. Are you sure you wish to continue?")
if question == False:
showinfo("No", "Cancelling action.")
else:
showinfo("Yes", "Continuing with Delprof...")
if question:
reply = subprocess.Popen(Command ...)
查看此代码片段:
exclude = ["BURSAR", "SHOP"]
if any ((name in machineName for name in exclude)):
question = askyesno('Warning', "That machine is on the exclude list. Are you sure you wish to continue?")
if question == False:
showinfo("No", "Cancelling action.")
else:
showinfo("Yes", "Continuing with Delprof...")
else:
reply = subprocess.Popen(Command ...)
'machineName' 从上方传入,然后我需要它询问 machineName 是否在排除列表中,但如果人们说是,则给他们选项以继续执行命令。
如何通过 else: 和 运行 命令传递代码?
谢谢,克里斯。
如果您将最后一个 else 替换为 if question:
,如果 question
为 True
,则其后的代码将仅 运行。如果你这样做,你应该在第一个 if.
question = True
exclude = ["BURSAR", "SHOP"]
question = True
if any ((name in machineName for name in exclude)):
question = askyesno('Warning', "That machine is on the exclude list. Are you sure you wish to continue?")
if question == False:
showinfo("No", "Cancelling action.")
else:
showinfo("Yes", "Continuing with Delprof...")
if question:
reply = subprocess.Popen(Command ...)