通过if / else拆分传递askyesno

时间:2015-01-22 09:58:11

标签: windows python-2.7 tkinter

请参阅以下代码段:

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 ...)

'机器名'从上面传入它,然后我需要它询问机器名是否在排除列表中的问题,但如果他们说是,则给人们选择继续命令。

如何通过单击Yes通过else传递代码:并运行命令?

谢谢,克里斯。

1 个答案:

答案 0 :(得分:0)

如果您使用if question:替换上一个其他内容,则只有questionTrue后才会运行后面的代码。如果你这样做,你应该在第一个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 ...)