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

标签 python linux gtk3

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

最佳答案

下面的 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()

一定要在 idel_add 调用之外将指针设置为监视,这一点很重要,否则它将不会被设置。

关于python - 在Gtk3中使用python将光标更改为沙漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9876479/

相关文章:

linux - 如果标签之间是值,如何在 html 标签之间 grep/sed

multithreading - 从其他线程执行 GTK 函数

python - 没有条目的 GTK3 组合框移动到有条目的 GTK3 组合框之后。为什么?

linux - 无法从局域网访问tomcat网页

linux - pushf在nasm中的使用

python - 自定义信号未传播

python - 如何在 pandas 中按行对数据进行分组

python - 如何在客户端模式下设置 `spark.driver.memory` - pyspark(版本2.3.1)

python - 没有导入候选人的实例

python - 如何在seaborn中切换两个类别的颜色?