在Gtk3中使用python将光标更改为沙漏

Ish*_*iri 2 python linux gtk3

有人可以提供一个代码片段,可以在Gtk3下使用python将光标更改为沙漏吗?

man*_*del 5

以下Window实现执行此操作:

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


class MainWindow(Gtk.Window):
    """Example window."""

    def __init__(self):
        """Create new instance."""
        super(MainWindow, self).__init__()
        self.set_title('Test Windows')

        box = Gtk.VBox()
        label = Gtk.Label("Just a label....")
        box.pack_start(label, True, True, 0)
        button = Gtk.Button(" and a button")
        box.pack_start(button, True, True, 0)

        self.add(box)
        self.connect("destroy", Gtk.main_quit)
        self.show_all()

    def set_watch(self):
        """Set the mouse to be a watch."""
        watch = Gdk.Cursor(Gdk.CursorType.WATCH)
        gdk_window = self.get_root_window()
        gdk_window.set_cursor(watch)

    def long_call(self):
        """Perform a long call."""
        time.sleep(10)             # your time consuming operation here
        arrow = Gdk.Cursor(Gdk.CursorType.ARROW)
        gdk_window = self.get_root_window()
        gdk_window.set_cursor(arrow)


window = MainWindow()
window.set_watch()
GObject.idle_add(window.long_call)
Gtk.main()
Run Code Online (Sandbox Code Playgroud)

将指针设置为在idel_add调用外观看是很重要的,否则将不会设置.