【问题标题】:Clock - "do stuff", wait 1sec, turned off "stuff" in python时钟 - “做东西”,等待 1 秒,在 python 中关闭“东西”
【发布时间】:2015-04-13 16:11:58
【问题描述】:

我正在尝试创建一个简单的循环来检查是否按下了某个键。如果是这样,则打开突出显示某个对象的线条。我希望那条线路只打开一秒钟甚至更短的时间——这只是为了响应反馈,让用户知道他在搬进来之前选择了他想要的。

我试图玩它,但无法让它工作,因为线路要么继续存在,要么根本没有激活。

我先定义边框:

border = visual.ShapeStim(win, vertices=iimage.verticesPix, units='pix', lineWidth=5, lineColor='red')
border_1 = visual.ShapeStim(win, vertices=image_2.verticesPix, units='pix', lineWidth=5, lineColor='green')

if key_resp_2.keys=='left':
    border.autoDraw=True
    timer=core.CountDownTimer(1)
    while timer.getTime()<0
        border.autoDraw=False

if key_resp_2.keys=='right':
    border_1.autoDraw=True
    timer=core.CountdownTimer(2)
    while timer.getTime()<0:
        border.autoDraw=False

【问题讨论】:

  • 您的代码严重不完整。您没有向我们展示您正在使用哪种 GUI/工具包(Tkinter?、WxPython?、PyGame/PySDL?)...因此我们无法建议使用哪种“.update()”或“.redraw ()" 方法,您可能必须在框架中调用才能触发“画布”与实际屏幕的同步。

标签: python timer clock countdown


【解决方案1】:
import time
#do stuff
time.sleep(1) #or whatever
#do stuff

【讨论】:

  • 我试图将它插入到我的“if”循环中,但没有创建突出显示的行,一切只花了 1 秒。导入时间 if key_resp_2.keys=='left':border.autoDraw=True time.sleep(1)border.autoDraw=False
猜你喜欢
  • 2013-02-03
  • 1970-01-01
  • 1970-01-01
  • 2021-10-28
  • 2020-06-26
  • 2010-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多