7

I have a tinter Toplevel window that I want to come up without a frame or a titlebar and slightly transparent, and then solid when the mouse moves over the window. To do this I am using both Toplevel.overrideredirect(True) and Toplevel.attributes('-alpha', 0.75). I am binding the <Enter> and <Leave> events to a function for this.

These all work when tried separately, but when I have the overrideredirect set to True, the bindings for the mouse entering and leaving no longer works. The binding calls when I click on the window, and then when I move the mouse, but not when the curser enter or leave the window.

I have also tried binding these to a Frame, but with no further luck.

toplevel = Toplevel(root)
toplevel.overrideredirect(True)
toplevel.attributes('-alpha', 0.75)
toplevel.bind('<Enter>', lambda x: mouseMovement(command='enter'))
toplevel.bind('<Leave>', lambda x: mouseMovement(command='leave'))
def mouseMovement(command):
    print('Callback: ' + command)
    if command == 'enter':
        toplevel.attributes('-alpha', 1)
    elif command == 'leave':
        toplevel.attributes('-alpha', 0.75)

I have tried using the answer to the similar question here, but this results in a window that has all the standard OS decorations, but the close, minimise, and enlarge buttons are simply disabled. Is there a way where I can get rid of the titlebar, but still keep my bindings?

Cailean Wilkinson
  • 1,420
  • 2
  • 19
  • 32
  • Just a comment on your code style: How come you do `lambda x: mouseMovement(command='enter')` when `command` is a positional argument of `mouseMovement`? Doing `lambda x: mouseMovement('enter')` would work just fine. –  Dec 21 '13 at 19:25
  • That's simply the way I prefer to write it. I didn't think it affected the code at all. – Cailean Wilkinson Dec 21 '13 at 19:28
  • No, it doesn't. I was just curious. –  Dec 21 '13 at 19:28
  • Would it be more pythonic for me to have positional arguments without `command=`? – Cailean Wilkinson Dec 21 '13 at 19:30
  • Yea, I would say so. When people see `parameter=value`, they think of keyword arguments. But your function is expecting positional arguments. So, it is a little inconsistent. But, like I said above, it won't affect the operation of the code. It's merely a style thing. –  Dec 21 '13 at 19:34
  • 2
    What platform? Is this on OSX? – Bryan Oakley Jul 29 '17 at 22:26
  • Seems to be working fine on Windows 7. – Nae Jan 18 '18 at 17:13
  • Well it seems to be working fine on Windows 10 too. – Itsjul1an May 28 '21 at 18:16

1 Answers1

3

On X Windows this can be handled using appropriate Extended Window Manager Hints to request the window manager to decorate the toplevel the way desired. This sounds like a splash screen window so 'splash' is likely to be appropriate here. For this use the wm_attributes -type parameter eg:

toplevel.wm_attributes('-type', 'splash')

will have the toplevel decorated as for a splash screen dialog which usually means no title bar. If you apply this to an already mapped window, you will need to withdraw and re-map (call wm_deiconify) to get the window manager to apply its settings for the new hint type.

patthoyts
  • 32,320
  • 3
  • 62
  • 93