shaped_frame_mobile.py

来自「wxPython的基本示例程序」· Python 代码 · 共 65 行

PY
65
字号
import wximport imagesclass ShapedFrame(wx.Frame):    def __init__(self):        wx.Frame.__init__(self, None, -1, "Shaped Window",                style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER )        self.hasShape = False        self.delta = wx.Point(0,0)        self.bmp = images.getVippiBitmap()        self.SetClientSize((self.bmp.GetWidth(), self.bmp.GetHeight()))        dc = wx.ClientDC(self)        dc.DrawBitmap(self.bmp, 0,0, True)        self.SetWindowShape()        self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)        self.Bind(wx.EVT_MOTION, self.OnMouseMove)        self.Bind(wx.EVT_RIGHT_UP, self.OnExit)        self.Bind(wx.EVT_PAINT, self.OnPaint)        self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowShape)    def SetWindowShape(self, evt=None):        r = wx.RegionFromBitmap(self.bmp)        self.hasShape = self.SetShape(r)    def OnDoubleClick(self, evt):        if self.hasShape:            self.SetShape(wx.Region())            self.hasShape = False        else:            self.SetWindowShape()    def OnPaint(self, evt):        dc = wx.PaintDC(self)        dc.DrawBitmap(self.bmp, 0,0, True)    def OnExit(self, evt):        self.Close()    def OnLeftDown(self, evt):        self.CaptureMouse()        pos = self.ClientToScreen(evt.GetPosition())        origin = self.GetPosition()        self.delta = wx.Point(pos.x - origin.x, pos.y - origin.y)    def OnMouseMove(self, evt):        if evt.Dragging() and evt.LeftIsDown():            pos = self.ClientToScreen(evt.GetPosition())            newPos = (pos.x - self.delta.x, pos.y - self.delta.y)            self.Move(newPos)    def OnLeftUp(self, evt):        if self.HasCapture():            self.ReleaseMouse()if __name__ == '__main__':    app = wx.PySimpleApp()    ShapedFrame().Show()    app.MainLoop()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?