Python:Tkinter

编程入门 行业动态 更新时间:2024-10-19 06:27:25
本文介绍了Python:Tkinter -- 如何让光标显示忙碌状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试让 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:

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

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 06:51:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390700.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python   Tkinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!