【问题标题】:Sequentially updating tkinter canvas顺序更新 tkinter 画布
【发布时间】:2018-05-07 16:32:35
【问题描述】:

按下按钮即可激活以下呼叫。

def ON():
  print("System Initiated")
  var.set("System Initiated")
  AC1 = circuitD.create_oval(375,155,400,180, fill= 'green')
  DCM = circuitD.create_oval(375,425,400,450, fill= 'green')
  DC2 = circuitD.create_oval(367,513,392,538, fill= 'green')
  DC1 = circuitD.create_oval(313,513,338,538, fill= 'green')
  DC3 = circuitD.create_oval(423,513,448,538, fill= 'green')
  DC4 = circuitD.create_oval(477,513,502,538, fill= 'green')

它只是在画布的不同区域绘制了 6 个绿色圆圈。 我想按顺序绘制它们,延迟一秒。我尝试在每行之间使用time.sleep(seconds) sn-p。

def ON():
  print("System Initiated")
  var.set("System Initiated")
  AC1 = circuitD.create_oval(375,155,400,180, fill= 'green')
  time.sleep(seconds)
  DCM = circuitD.create_oval(375,425,400,450, fill= 'green')
  time.sleep(seconds)
  DC2 = circuitD.create_oval(367,513,392,538, fill= 'green')
  time.sleep(seconds)
  DC1 = circuitD.create_oval(313,513,338,538, fill= 'green')
  time.sleep(seconds)
  DC3 = circuitD.create_oval(423,513,448,538, fill= 'green')
  time.sleep(seconds)
  DC4 = circuitD.create_oval(477,513,502,538, fill= 'green')

睡眠功能将整个绘制序列延迟设定的时间量,然后继续一次绘制所有 6 个圆。似乎 sleep 函数只是适当地延迟了 shell 输出。

我的问题是,有没有办法延迟圆圈出现在画布上?或者有没有办法在每个time.sleep(seconds) 之后实时更新画布?

提前谢谢你。

【问题讨论】:

标签: python canvas tkinter


【解决方案1】:

如果您不介意整个程序在序列期间锁定,那么您可以在睡眠后添加circuitD.update()

否则,您将不得不使用after 调用,但这会影响您保留对已创建对象的引用的能力。你用这些参考资料做什么?

如果您提供Minimal, Complete, and Verifiable example,我可以举个例子。

【讨论】:

  • 'circuitD.update()' 对我来说很好用。它是一个启动过程,因此锁定程序是应该发生的。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-02
  • 2019-12-30
相关资源
最近更新 更多