Tartalomjegyzék

< wxPython GUI

wxPython mozgatás

Gomb mozgatása egérrel

mozgatas.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, parent):
        super(MainFrame, self).__init__(parent)
 
        self.panel = wx.Panel(self)
        self.button1 = wx.Button(self, label='Mehet')
 
        self.button1.Bind(wx.EVT_MOTION, self.onMotion)
        self.button1.Bind(wx.EVT_LEFT_DOWN, self.onButtonLeftDown)
        self.button1.Bind(wx.EVT_LEFT_UP, self.onButtonLeftUp)
 
        self.enableMove=False
 
    def onMotion(self, event):
        if self.enableMove:
            egerPosInWindow = self.ScreenToClient(wx.GetMousePosition())
            event.GetEventObject().SetPosition(egerPosInWindow-self.gombOriginPos)
 
    def onButtonLeftDown(self, event):
        self.gombOriginPos = event.GetPosition()
        self.enableMove = True
 
    def onButtonLeftUp(self, event):
        self.enableMove = False
 
 
class SimpeApp(wx.App):
    def OnInit(self):
        mainFrame = MainFrame(None)
        mainFrame.Show()
        return True
 
 
app = SimpeApp()
app.MainLoop()

Két gomb mozgatása

mozgatas.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, parent):
        super(MainFrame, self).__init__(parent)
 
        self.panel = wx.Panel(self)
        self.button1 = wx.Button(self, label='Mária')
        self.button2 = wx.Button(self, label='Béla')
 
        self.button1.Bind(wx.EVT_MOTION, self.onMotion)
        self.button1.Bind(wx.EVT_LEFT_DOWN, self.onButtonLeftDown)
        self.button1.Bind(wx.EVT_LEFT_UP, self.onButtonLeftUp)
 
        self.button2.Bind(wx.EVT_MOTION, self.onMotion)
        self.button2.Bind(wx.EVT_LEFT_DOWN, self.onButtonLeftDown)
        self.button2.Bind(wx.EVT_LEFT_UP, self.onButtonLeftUp)
 
        self.enableMove=False
 
    def onMotion(self, event):
        if self.enableMove:
            egerPosInWindow = self.ScreenToClient(wx.GetMousePosition())
            event.GetEventObject().SetPosition(egerPosInWindow-self.gombOriginPos)
 
    def onButtonLeftDown(self, event):
        self.gombOriginPos = event.GetPosition()
        self.enableMove = True
 
    def onButtonLeftUp(self, event):
        self.enableMove = False
 
 
class SimpeApp(wx.App):
    def OnInit(self):
        mainFrame = MainFrame(None)
        mainFrame.Show()
        return True
 
 
app = SimpeApp()
app.MainLoop()