Set the behavior of the Python window when the mouse is over and outside it

Asked

Viewed 179 times

0

I am using Pygtk in Python 2.7 and would like to set win.set_decorated(False) when the mouse is outside the window and win.set_decorated(True) when the mouse is over the window. How to do?

  • Post the relevant code that has sff, so we know how to help

  • @Miguel, I believe that the code I have is irrelevant in this case, since the solution is based on the state of the mouse on the window, launching these two situations that I mentioned.

  • @Miguel, I made a mistake when posting the functions cited, I beg your pardon. I edited the post.

  • I’ll take a look. Ha ok so didn’t transfer it right?

  • @Miguel thanks. It’s about taking out the edges and the title bar of the window with the set_decorated based on the mouse being or not on the window.

1 answer

1


There is a small bug but I will try to get around it. The event however is 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 window title bar as not over the window.

You can test that with win.set_opacity(0.5) in the mouse_leave() and win.set_opacity(1) in the mouse_enter(), instead of set_decorated()

  • True, the problem is to fix this title bar collapse as Leave-notify-Event is treating the title bar as outside the window. I am searching a lot here to try to fix this bug, but unsuccessfully yet. :(

  • It may not be possible. Have you seen this in a window? I don’t think I’ve seen this feature. However I’ll also see if I discover something

  • So I think it’s not impossible if I can map the coordinates of the screen and manipulate the window decoration based on that. But it may not be feasible, since I managed to do what I expect by clicking outside the window and returning with the decoration by clicking again on the window. It is much less costly in terms of processing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.