[[oktatas:programozás:python:wxpython_gui|< wxPython GUI]]
====== wxPython mozgatás ======
* **Szerző:** Sallai András
* Copyright (c) Sallai András, 2020
* [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]]
* Web: https://szit.hu
===== Gomb mozgatása egérrel =====
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 =====
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()