小编Mic*_*nen的帖子

如何在python gtk3应用程序中将光标更改为沙漏

我有一个需要很长时间才能执行的函数,并且我试图在执行函数期间将光标更改为沙漏。但它只在第一次调用函数时有效。我正在这样做(它在按钮的 on_click 事件处理程序中):

from gi.repository import Gtk, Gdk, GObject
import time

def on_grabbtn_clicked(self, button):
    # Change the cursor to hour Glass
    cursor = Gdk.Cursor.new(Gdk.CursorType.WATCH)
    self.window.get_root_window().set_cursor(cursor)

    # lenghty process here
    time.sleep(10)

     # Set the cursor to normal Arrow
    cursor = Gdk.Cursor.new(Gdk.CursorType.ARROW)
    self.window.get_root_window().set_cursor(cursor)
Run Code Online (Sandbox Code Playgroud)

window 是一个使用 Glade/GtkBuilder 构建的窗口,名为...window。我__init__()在窗口类中得到了一个句柄,如下所示:

self.window = self.builder.get_object('window')
Run Code Online (Sandbox Code Playgroud)

正如我所说,沙漏仅在我第一次单击按钮时出现。第二次就不行了。所以我做错了。但我做错了什么?

python cursor gtk3

5
推荐指数
1
解决办法
4467
查看次数

标签 统计

cursor ×1

gtk3 ×1

python ×1