Python Tkinter不更新游标

Python Tkinter不更新游标,python,tkinter,cursor,windows-10,Python,Tkinter,Cursor,Windows 10,我正试图在程序忙时更新光标 此代码段适用于: import tkinter as tk def button(): root.configure(cursor="watch") root = tk.Tk() root.geometry("300x500") button_1 = tk.Button(master=root,command=button,width=10) button_1.grid() root.mainloop() 当我点击按钮时,光标会改变 但这个片段失败了: im

我正试图在程序忙时更新光标

此代码段适用于:

import tkinter as tk
def button():
    root.configure(cursor="watch")
root = tk.Tk()
root.geometry("300x500")
button_1 = tk.Button(master=root,command=button,width=10)
button_1.grid()
root.mainloop()
当我点击按钮时,光标会改变

但这个片段失败了:

import tkinter as tk
def button():
    root.configure(cursor="watch")
    input("Force a pause")
root = tk.Tk()
root.geometry("300x500")
button_1 = tk.Button(master=root,command=button,width=10)
button_1.grid()
root.mainloop()
它仅在我激活另一个窗口或输入一些虚拟输入后更新光标

我试着加上

root.configure(cursor="watch")
root.update()
但是它仍然不起作用,而且tk的人说在回调中添加更新是个坏主意

欢迎提出任何建议


谢谢您的时间。

您的代码会更新光标,但只有在您繁忙的进程终止后才会更新光标。 因此,您可以在线程中执行繁忙的进程,以防止用户界面冻结

import tkinter as tk
import threading

def worker():
    for x in range(0, 100000):
        print(x)
    root.config(cursor="arrow")

def button():
    root.config(cursor="watch")
    threading.Thread(target=worker).start() 

root = tk.Tk()
root.geometry("300x500")
root.config(cursor="arrow")

button_1 = tk.Button(master=root, command=button, width=10)
button_1.grid()

root.mainloop()

工作是一种享受。谢谢