![](/img/trans.png)
[英]How to create text on a tkinter canvas and change the text in the canvas?
[英]How to use tkinter Canvas to create multiple text one time?
例如:
for i in range(10000):
canvas.create_text(10*i,100,text='test',fill='red')
主 window 在運行這部分時卡住了。 加載文本時如何避免它?
您可以使用after()
替換 for 循環,這樣它就不會阻塞mainloop
:
def show_text(n=0):
# show 20 text in each iteration
for i in range(20):
y, x = divmod(n+i, 20)
canvas.create_text(x*50, y*10, text='test', fill='red', anchor='nw')
n += 20
if n < 10000:
canvas.after(1, show_text, n)
show_text() # start the after() loop
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.