Define window behavior in Python when mouse is on and off

0

I'm using PyGTK in Python 2.7 and would like to set win.set_decorated(False) when the mouse is out of the window and win.set_decorated(True) when the mouse is over the window. How to do?

    
asked by anonymous 08.06.2016 / 14:31

1 answer

1

It has a small bug but I'll try to get around it. The event is however being detected.

import gtk

def mouse_enter(win, event):
    win.set_decorated(True)

def mouse_leave(win, event):
    win.set_decorated(False)

win = gtk.Window()
win.set_decorated(False)
win.connect('enter-notify-event', mouse_enter)
win.connect('leave-notify-event', mouse_leave)
win.connect('delete-event', gtk.main_quit)
win.show_all()
gtk.main()

The problem is that it identifies the mouse over borders and the title bar of the window as not being over the window.

You can test this with win.set_opacity(0.5) on mouse_leave() and win.set_opacity(1) on mouse_enter() instead of set_decorated()

    
08.06.2016 / 15:10