Python 如何在特定操作发生之前停止程序
使用python和tkinter,是否有一种方法可以运行程序的一部分,然后停止它,直到用户单击特定按钮,然后继续运行 我的意思是: 功能-停止-点击按钮-继续运行 这方面的必要代码:Python 如何在特定操作发生之前停止程序,python,tkinter,Python,Tkinter,使用python和tkinter,是否有一种方法可以运行程序的一部分,然后停止它,直到用户单击特定按钮,然后继续运行 我的意思是: 功能-停止-点击按钮-继续运行 这方面的必要代码: def yellowClick(): yellow.configure(activebackground="yellow3") yellow.after(500, lambda: yellow.configure(activebackground="yellow")) yellow = Tkin
def yellowClick():
yellow.configure(activebackground="yellow3")
yellow.after(500, lambda: yellow.configure(activebackground="yellow"))
yellow = Tkinter.Button(base, bd="0", highlightthickness="0",
width="7", height="5", activebackground="yellow",
bg="yellow3", command = yellowClick)
yellow.place(x = 30, y = 50)
def blueClick():
blue.configure(activebackground="medium blue")
blue.after(500, lambda: blue.configure(activebackground="blue"))
blue = Tkinter.Button(base, bd="0", highlightthickness="0",
width="7", height="5", activebackground="blue",
bg="medium blue", command = blueClick)
blue.place(x = 125, y = 50)
def redClick():
red.configure(activebackground="red3")
red.after(500, lambda: red.configure(activebackground="red"))
red = Tkinter.Button(base, bd="0", highlightthickness="0",
width="7", height="5", activebackground="red",
bg = "red3", command = redClick)
red.place(x = 30, y = 145)
def greenClick():
green.configure(activebackground="dark green")
green.after(500, lambda: green.configure(activebackground="green4"))
green = Tkinter.Button(base, bd="0", highlightthickness="0",
width="7", height="5", activebackground="green4",
bg="dark green", command = greenClick)
green.place(x = 125, y = 145)
def showSequence():
r = random.randint(1, 4)
if r == 1:
yellow.configure(bg="yellow")
yellow.after(1000, lambda: yellow.configure(bg="yellow3"))
elif r == 2:
blue.configure(bg="blue")
blue.after(1000, lambda: blue.configure(bg="medium blue"))
elif r == 3:
red.configure(bg="red")
red.after(1000, lambda: red.configure(bg="red3"))
elif r == 4:
green.configure(bg="green4")
green.after(1000, lambda: green.configure(bg="dark green"))
这是一个西蒙游戏,我需要运行这个函数一次,然后让它停止,直到玩家点击一个按钮,然后返回这个函数。这是第一次。我需要以一种方式连接showsequence函数,使其在单击按钮之前停止,但我不知道如何连接
在此情况下,按时间停止程序将不起作用,我的意思是等待特定操作发生。请查看此代码示例。它按原样工作,复制/通过它,它将运行。没有循环。它等待按钮点击。我认为您可以通过将随机颜色图案加载到“答案”列表中来初始化程序,该列表基本上可以是您的级别。
如果可能,请添加一段简单的代码。有人可能会发布一个更好的方法,但你可以使用一个带有100ms睡眠功能的while循环。例如:
while True:检查其他时间。sleep(0.1)