The wxPython Phoenix project can be used with Python version 2 and version 3. The project applies pretty much the familiar wxPython code. Here we are testing a dragable borderless frame.
Dragable Frame using wxPython (Phoenix)
''' pwx_drag_frame101.py
experiments with wxPython's Frame styles
create a borderless window that is dragable
for Python3 downloaded project Phoenix latest version
for instance
wxPython_Phoenix-2.9.5.81-r74058-win32-py3.3.tar.gz
from
http://wxpython.org/Phoenix/snapshot-builds/
then simply extracted the wx folder to
C:\Python33\Lib\site-packages
tested with Python27/33 and wx(Phoenix) by vegaseat 29may2013
'''
import wx
class DragFrame(wx.Frame):
def __init__(self):
style = wx.CLIP_CHILDREN|wx.STAY_ON_TOP|wx.FRAME_NO_TASKBAR|\
wx.NO_BORDER|wx.FRAME_SHAPED
wx.Frame.__init__(self, None, size=(300, 200), style=style)
self.Bind(wx.EVT_KEY_UP, self.on_key_press)
self.Bind(wx.EVT_MOTION, self.on_mouse)
self.Bind(wx.EVT_PAINT, self.on_paint)
self.SetTransparent(200)
self.Show(True)
def on_key_press(self, event):
'''
quit if user presses Esc key (27)
'''
if event.GetKeyCode() == 27:
self.Close(force=True)
else:
event.Skip()
def on_mouse(self, event):
'''
implement dragging
'''
if not event.Dragging():
self._dragPos = None
return
self.CaptureMouse()
if not self._dragPos:
self._dragPos = event.GetPosition()
else:
pos = event.GetPosition()
displacement = self._dragPos - pos
self.SetPosition( self.GetPosition() - displacement )
def on_paint(self, event):
# wx.PaintDC() creates a drawing canvas
dc = wx.PaintDC(self)
# set the canvas background
dc.SetBackground(wx.Brush('white'))
dc.Clear()
# wx.Brush(color, style)
dc.SetBrush(wx.Brush('green', wx.CROSS_HATCH))
# apply the brush to a rectangle
dc.DrawRectangle(0, 0, 300, 200)
# info
s = "Drag me! \nPress Escape to exit"
dc.DrawText(s, 20, 15)
app = wx.App(0)
frame = DragFrame()
app.MainLoop()
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.