注意的是如果Frame上面还有控件,需要在空间上绑定 wx.EVT_MOTION , wx.EVT_LEFT_DOWN 事件
本文以下源码来源于 https://bytes.com/topic/python/answers/699951-move-windows-without-title-bar-wxpython
import wx
 
def create(parent):
    return Frame1(parent)
 
[wxID_FRAME1] = [wx.NewId() for _init_ctrls in range(1)]
 
class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(22, 22),
                size=wx.Size(400, 250), style=wx.NO_BORDER, title='Frame1')
        self.Bind(wx.EVT_MOTION, self.OnFrame1Motion)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnFrame1LeftDown)
 
    def __init__(self, parent):
        self._init_ctrls(parent)
        self.lastMousePos = wx.Point(0, 0)
 
    def OnFrame1Motion(self, event):
        if event.LeftIsDown():
            windowX = self.lastMousePos[0]
            windowY = self.lastMousePos[1]
            screenX = wx.GetMousePosition()[0]
            screenY = wx.GetMousePosition()[1]
            self.Move(wx.Point(screenX - windowX, screenY - windowY))
        event.Skip()
 
    def OnFrame1LeftDown(self, event):
        self.lastMousePos = event.GetPosition()
        event.Skip()
 
    def closeWindow(self, e):
        self.Destroy() #prevent memory leak
 
if __name__ == "__main__":
    app = wx.App()
    frame = create(None)
    frame.Show()
    app.MainLoop()

发表评论

电子邮件地址不会被公开。 必填项已用*标注