如何防止用户拖动窗口/框架
我需要创建一个简单的应用程序,不能调整大小、最小化、最大化和移动。我已经能够满足所有这些要求,但要感谢这个答案,但我找不到如何防止窗口拖动。
我尝试改编这个C++答案:当触发移动事件时,我只是将窗口移回到原来的位置,但它不是很干净:它使窗口摇晃,有时会最小化所有其他正在运行的应用程序。另外,“移动”选项是系统菜单中可用的样式,我想禁用它。
那么如何在单击标题栏时禁用拖动窗口并禁用系统菜单中的“移动”选项呢?
我正在运行 Windows 10
、Python 3.10
和 wxpython 4.1.1
。
def __init__(self):
# stuffs ...
self.Center()
self.Show()
x, y = self.GetPosition()
self.x = x
self.y = y
self.Bind(wx.EVT_MOVE, self.on_move)
def on_move(self, ev):
ev.Skip()
self.Move(self.x, self.y)
I need to create a simple app that cannot be resized, minimised, maximised and moved. I've been able to fulfill all this requirements but one thanks to this answer but I cant find how to prevent window dragging.
I've tried to adapt this C++ answer : when move event is trigerred, I just move back the window to its original position, but it's not very clean : it makes the windows shaky and sometimes minimize all other running apps. Also, the "Move" options is style available from system menu and I'd like to disable it.
So how can I disable dragging the window when clicking on title bar and disable Move option from system menu ?
I'm running Windows 10
, Python 3.10
and wxpython 4.1.1
.
def __init__(self):
# stuffs ...
self.Center()
self.Show()
x, y = self.GetPosition()
self.x = x
self.y = y
self.Bind(wx.EVT_MOVE, self.on_move)
def on_move(self, ev):
ev.Skip()
self.Move(self.x, self.y)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我永远不会建议有一个不可移动的窗口,但如果这是一个游戏规则改变者,在您的具体情况下,那么您可以定义一个没有框架因此不可移动的窗口。
缺点是您必须自己在窗口中添加任何标题和关闭功能。
我还建议将其设为
Always_on_top
。正如您所看到的,您获得了限制,但失去了与桌面上其他窗口的兼容性。
I would never recommend having a window that is not moveable but if that is a game changer, in your specific situation, then you could define a window that has no frame and thus is not moveable.
The downside is that you would have to include any caption and a close facilty within the window yourself.
I'd also recommend making it
Always_on_top
.As you can see, you gain the restrictions but lose compatability with other windows on the desktop.
我不运行 Windows 操作系统,因此无法测试
wx.EVT_MOVE_END
事件,这应该会给您带来更好的结果。样式
只为您提供一个关闭框,并防止窗口包含在任务栏中。我相信,至少在应用程序级别上,覆盖操作系统提供的
Move
功能是不可能的。I don't run windows OS so I can't test the
wx.EVT_MOVE_END
event, which should give you a better result.The
style
gives you just a Close box and prevents the window being included in the taskbar.Overriding the
Move
ability provided by the OS, is I believe, not possible, at an App level at least.