问题描述
限时送ChatGPT账号..我有一个不带框架或标题栏且略透明的着色顶层窗口,当鼠标移到窗口上时,它会变成实心窗口.为此,我同时使用 Toplevel.overrideredirect(True)
和 Toplevel.attributes('-alpha', 0.75)
.为此,我将
和
事件绑定到一个函数.
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.
这些在单独尝试时都有效,但是当我将 overrideredirect 设置为 True 时,鼠标进入和离开的绑定不再有效.当我点击窗口时绑定调用,然后当我移动鼠标时,而不是当光标进入或离开窗口时.
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?
推荐答案
在 X Windows 上,这可以使用适当的扩展窗口管理器提示来处理,以请求窗口管理器以所需的方式装饰顶层.这听起来像一个闪屏窗口,所以闪屏"在这里很可能是合适的.为此,请使用 wm_attributes -type 参数,例如:
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')
将顶层装饰为初始屏幕对话框,这通常意味着没有标题栏.如果您将此应用于已映射的窗口,您将需要撤回并重新映射(调用 wm_deiconify)以使窗口管理器应用其对新提示类型的设置.
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.
这篇关于Tkinter overrideredirect 不再接收事件绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论