我正在前端工作,需要在单击按钮时将手形光标更改为忙碌光标。但我的代码抛出“类型错误”。我只想让代码显示一个按钮,单击该按钮会从手形光标更改为繁忙光标,然后返回正常光标。
这是我迄今为止尝试过的代码:
import threading
from threading import Thread
from threading import Event
import queue
sem=threading.Semaphore()
def setup_for_long_running_task(self):
print("start")
self.f1.config(cursor="wait") # Set the cursor to busy
sem.acquire()
return_que = queue.Queue(1)
workThread = Thread(target=lambda q, w_self: \
q.put(self.long_running_task()),
args=return_que)
workThread.start()
self.f1.after(5000,use_results_of_long_running_task(self,workThread,return_que)) # 500ms is half a second
sem.release()
print("stop")
def long_running_task(self):
Event().wait(3.0) # Simulate long running task
def use_results_of_long_running_task(self, workThread,return_que):
ThreadRunning = 1
while ThreadRunning:
Event().wait(0.1) # this is set to .1 seconds. Adjust for your process
ThreadRunning = workThread.is_alive()
while not …Run Code Online (Sandbox Code Playgroud)