PyGTK隐藏光标 [英] PyGTK Hide Cursor

查看:386
本文介绍了PyGTK隐藏光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题很简单,我如何使用PyGTK隐藏活动窗口上的光标?

The question is simple how can I hide the cursor on an active window using PyGTK???

这是一个基本的应用程序, / p>

Here's a basic app I made to learn this...

#!/usr/bin/env python

import gtk

class app:

  def __init__(self):
    window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    window.set_title("TestApp")
    window.set_default_size(400,200)
    pixmap = gtk.gdk.Pixmap(None, 1, 1, 1)
    color = gtk.gdk.Color()
    cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0)
    window.set_cursor(cursor)
    window.connect("destroy", gtk.main_quit)    
    window.show_all()

app()
gtk.main()

显然,只是一个窗口,但是当我去尝试和运行它。我收到此错误。

Obviously all it is, is just a window, however when I went to try and run it. I got this error.

AttributeError:'gtk.Window'对象没有属性'set_cursor'

AttributeError: 'gtk.Window' object has no attribute 'set_cursor'

看到这个错误,我意识到gt.Window将无法做到,但gtk.gdk.Window会。

After seeing that error I realized gt.Window won't be able to do it, but gtk.gdk.Window will. However how can I convert this basic window so it'll hide the cursor.

推荐答案

PyGTK常见问题,您应该将光标置于 realize 信号。如果您不等待 实现 信号, gtk.gdk.window 尚未创建,因此您无法更改光标。

As stated in the PyGTK FAQ, you should set the cursor on the realize signal. If you don't wait for the realize signal, the gtk.gdk.window hasn't been created yet, so you can't change the cursor.

所以,你可以这样做:

#!/usr/bin/env python

import gtk

class app:

  def __init__(self):
    window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    window.set_title("TestApp")
    window.set_default_size(400,200)
    window.connect("realize", self.realize_cb)
    window.connect("destroy", gtk.main_quit)    
    window.show_all()

  def realize_cb(self, widget):
    pixmap = gtk.gdk.Pixmap(None, 1, 1, 1)
    color = gtk.gdk.Color()
    cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0)
    widget.window.set_cursor(cursor)

app()
gtk.main()

这篇关于PyGTK隐藏光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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