尝试拖动按钮时出现错误-> wx._core.wxAssertionError:

时间:2019-05-10 17:04:24

标签: wxpython

我正在尝试拖动按钮。我上了一堂课做拖拽。当我运行代码时,它就会运行;但是当我尝试单击按钮或尝试将其拖动时,出现此错误

错误:

  

wx._core.wxAssertionError:C ++断言“ tlw”在/Users/robind/projects/buildbots/macosx-vm6/dist-osx-py37/Phoenix/ext/wxWidgets/src/osx/window_osx.cpp(762)失败)在DoScreenToClient()中:缺少顶级窗口

下面是代码:

class window (wx.Frame):
    def __init__ (self, parent, id):
        wx.Frame.__init__ (self, parent, id, "Solitaire", size = (1300, 800))
        self.add_menubar()
        self.panel = wx.Panel(self)
        img = 'background.jpg'
        self.bmp = wx.Image(img, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        self.bitmap = wx.StaticBitmap(self.panel, -1, self.bmp)


        c2I = wx.Image('C2.png', wx.BITMAP_TYPE_ANY).Rescale(150, 200).ConvertToBitmap()
        self.c2 = wx.BitmapButton(self.bitmap, -1, c2I, pos = ((100, 100)))
        mvc2 = move(self.c2)
        self.Bind(wx.EVT_LEFT_DOWN, mvc2.onDown)
        self.c2.Bind(wx.EVT_LEFT_DOWN, mvc2.onButton)
        self.c2.Bind(wx.EVT_MOTION, mvc2.drag)
        self.c2.Bind(wx.EVT_LEFT_UP, mvc2.onRelease)




class move(wx.BitmapButton):
    def __init__ (self, object):
        wx.BitmapButton.__init__(self)
        self.object = object

        self.delta = ((0, 0))
    def drag(self, event):
        if event.Dragging():
            x, y = self.ScreenToClient(self.object.ClientToScreen(event.GetPosition()))
            fp = (x - self.delta[0], y - self.delta[1])
            self.object.Move(fp)

    def onRelease(self, event):
        if self.object.HasCapture():
            self.object.ReleaseMouse()

    def onDown(self, event):
        print("on frame")
        event.Skip()

    def onButton(self, event):
        self.object.CaptureMouse()
        x, y = self.ScreenToClient(self.object.ClientToScreen(event.GetPosition()))
        originx, originy = self.object.GetPosition()
        dx = x - originx
        dy = y - originy
        self.delta = ((dx, dy))

基本上,我想在屏幕上拖放按钮。 请帮忙。 预先感谢

0 个答案:

没有答案