顺序更新tkinter画布

2024-06-25 23:06:56 发布

您现在位置:Python中文网/ 问答频道 /正文

按下按钮即可激活以下呼叫。你知道吗

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)代码段。你知道吗

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

sleep函数将整个绘制顺序延迟一段时间,然后继续一次绘制所有6个圆。似乎sleep函数只能适当地延迟shell输出。你知道吗

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

先谢谢你。你知道吗


Tags: timeonvardef画布createsleepgreen
1条回答
网友
1楼 · 发布于 2024-06-25 23:06:56

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

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

如果您提供Minimal, Complete, and Verifiable example,我可以给出一个示例。你知道吗

相关问题 更多 >