python如何设置窗口保持显示,Python如何保持MessageboxW在所有其他窗口之上?

Context:

I have a small script that alerts the user of an event by creating a message box using the Windows in built message box (Ref: MSDN MessageBox) which is imported using ctypes. This script is for Windows OS.

Problem:

Currently, the message box will appear on top of all other windows, but because it's such a small window, a user can easily click onto another window which could hide the message box.

What I want

I want to keep the message box always on top of other windows. If this can't be done, then alternatively is there a way to increase the dimensions of the message box?

Example Code:

import ctypes

ctypes.windll.user32.MessageBoxW(0, text, title, 0x00010000)

解决方案import ctypes

text = 'Using MB_SYSTEMMODAL'

title = 'Some Title'

ctypes.windll.user32.MessageBoxW(0, text, title, 0x1000)

MB_SYSTEMMODAL (0x1000) has the WS_EX_TOPMOST (0x40000) style.

The MessageBoxEx function seems to work good with using just

the WS_EX_TOPMOST (0x40000) style.

import ctypes

text = 'Using WS_EX_TOPMOST'

title = 'Some Title'

ctypes.windll.user32.MessageBoxExW(0, text, title, 0x40000)

The MessageBox function has no parameters to change size. Perhaps

an alternative like tkinter or another gui toolkit might be able

to change messagebox size (though it maybe not if it just a wrapper

for MessageBoxW) or you could perhaps create a custom window to use.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值