更改 Pygtk 应用程序中的游标类型
在我的应用程序中,我想在鼠标离开和输入事件时更改所有按钮的光标类型。为此,我想编写通用代码,而不是将每个按钮与适当的信号连接起来。
这是它的示例代码。
import gtk
class Button(gtk.Button):
__gsignals__ = {
"leave" : "override",
"enter" : "override"
}
def do_leave(self):
self.window.set_cursor(None)
def do_enter(self):
print "Enter"
self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2))
class EventBox:
def __init__(self):
window = gtk.Window()
vbox = gtk.VBox()
label = gtk.Label("Change Cursor")
vbox.pack_start(label, False, False)
bt = gtk.Button('Ok')
bt.connect('clicked', self.on_click, window)
vbox.pack_start(bt, False, False)
eventbox = gtk.EventBox()
window.set_size_request(400,400)
window.add(eventbox)
eventbox.add(vbox)
window.show_all()
def on_click(self, widget, window, *args):
print "On click"
window.destroy()
NextWin()
def mouse_enter_event(self, widget, *args):
print "Enter"
widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2))
class NextWin:
def __init__(self):
window = gtk.Window()
vbox = gtk.VBox()
label = gtk.Label("Change Cursor")
vbox.pack_start(label, False, False)
bt = gtk.Button('Ok')
vbox.pack_start(bt, False, False)
eventbox = gtk.EventBox()
window.connect("destroy", lambda w: gtk.main_quit())
window.set_size_request(400,400)
window.add(eventbox)
window.set_name('Next Window')
window.set_title('Next Window')
eventbox.add(vbox)
window.show_all()
gtk.Button = Button
EventBox()
gtk.main()
上面的代码适用于 gtk 按钮,但不适用于空地文件按钮。 林间空地文件按钮可能有什么问题?
我也在寻找更合适的方法来更改光标类型。 有人对上述代码有任何建议或更正吗?
In my application I want to change cursor type of all buttons, on mouse leave and enter events. for this, I want to write generalized code instead of connecting each button with appropriate signal.
here's an example code for it.
import gtk
class Button(gtk.Button):
__gsignals__ = {
"leave" : "override",
"enter" : "override"
}
def do_leave(self):
self.window.set_cursor(None)
def do_enter(self):
print "Enter"
self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2))
class EventBox:
def __init__(self):
window = gtk.Window()
vbox = gtk.VBox()
label = gtk.Label("Change Cursor")
vbox.pack_start(label, False, False)
bt = gtk.Button('Ok')
bt.connect('clicked', self.on_click, window)
vbox.pack_start(bt, False, False)
eventbox = gtk.EventBox()
window.set_size_request(400,400)
window.add(eventbox)
eventbox.add(vbox)
window.show_all()
def on_click(self, widget, window, *args):
print "On click"
window.destroy()
NextWin()
def mouse_enter_event(self, widget, *args):
print "Enter"
widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2))
class NextWin:
def __init__(self):
window = gtk.Window()
vbox = gtk.VBox()
label = gtk.Label("Change Cursor")
vbox.pack_start(label, False, False)
bt = gtk.Button('Ok')
vbox.pack_start(bt, False, False)
eventbox = gtk.EventBox()
window.connect("destroy", lambda w: gtk.main_quit())
window.set_size_request(400,400)
window.add(eventbox)
window.set_name('Next Window')
window.set_title('Next Window')
eventbox.add(vbox)
window.show_all()
gtk.Button = Button
EventBox()
gtk.main()
above code is working for gtk buttons but not working for glade file buttons.
what could be the problem with glade file buttons?
I'm also looking for more appropriate way to change cursor type.
Does anyone have any suggestion or correction for above code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道这已经放在这里有一段时间了,所以只是一个想法……也许在 Glade 之外重建你的 GUI(或一些模型)。这确实不是很难做到,而且文档也很棒。
然后,尝试连接鼠标光标更改代码,看看它是否有效。
I know this has been sitting here for a while, so just a thought...perhaps rebuild your GUI (or some mockup) outside of Glade. It really isn't very hard to do, and the documentation is fantastic.
Then, try and hook up your mouse cursor change codes, and see if it works.