Feb-03-2022, 11:22 AM
(This post was last modified: Feb-03-2022, 11:23 AM by philipbergwerf.)
I made this little example where a cursor is blinking on the canvas:
from tkinter import * from threading import Thread from time import sleep root = Tk() canvas = Canvas(root) canvas.pack() cursor_blink = True def cursor(): while cursor_blink: canvas.create_line(100,100,100,200,tag='cursor') sleep(0.5) canvas.delete('cursor') sleep(0.5) thread = Thread(target=cursor) thread.start() def reset_cursor(evt): # kill cursor thread? / this function is supposed to restart the thread; how? thread.start() root.bind('<ButtonRelease-1>', reset_cursor) root.mainloop()The goal is to reset the cursor immediately when clicking on the canvas. Currently it waits for the loop to complete before checking if the curs variable is still True. Is there maybe a different way without using sleep() to make the cursor blink?