Python:Tkinter -- 如何让光标显示忙碌状态 [英] Python:Tkinter -- How do I get cursor to show busy status

查看:49
本文介绍了Python:Tkinter -- 如何让光标显示忙碌状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 Tkinter 显示繁忙的光标.不幸的是,我一定遗漏了一些非常明显的东西.以下是一个非常简单的程序,可以重现我的问题:

I'm trying to make Tkinter show a busy cursor. Unfortunately, I must be missing something terribly obvious. Following is a very simple program that reproduces my problem:

 from Tkinter import *
 import time

 def do_something():
     print "starting"
     window.config(cursor="wait")
     time.sleep(5)
     window.config(cursor="")
     print "done"
     return

 root = Tk()
 menubar = Menu(root)
 filemenu = Menu(menubar, tearoff=0)
 filemenu.add_command(label="Do Something", command=do_something)
 filemenu.add_command(label="Exit", command=root.quit)
 menubar.add_cascade(label="File", menu=filemenu)
 root.config(menu=menubar)
 root.mainloop()

我没有看到光标有任何变化

I'm not seeing any change in the cursor

推荐答案

do_something 像这样:

def do_something():
 print "starting"
 root.config(cursor="wait")
 root.update()
 time.sleep(5)
 root.config(cursor="")
 print "done"

基本上,我做了三件事:

Basically, I did three things:

  1. root 替换 window(因为 window 未定义,root 是窗口的句柄).

  1. Replaced window with root (since window isn't defined and root is the window's handle).

在配置光标的行之后添加了 root.update().

Added root.update() just after the line that configures the cursor.

删除了不必要的return(这不会导致任何错误,但为什么会出现错误?).

Removed the unnecessary return (this didn't cause any errors, but why have it?).

这篇关于Python:Tkinter -- 如何让光标显示忙碌状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆