wxpython不规则窗体,wxpython窗体,#!/usr/bin/e
#!/usr/bin/env python#-*- coding:utf-8 -*-__author__ = "wangaibo168@163.com"import sys;reload(sys);sys.setdefaultencoding("utf-8");import wx;import os.path;class MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self,parent=None,id=-1,title="Shape窗体",pos=(100,100),style=wx.FRAME_SHAPED|wx.SIMPLE_BORDER|wx.STAY_ON_TOP); self.pt = wx.Point(0,0); img = wx.Image(os.path.sep.join([os.path.curdir,'bg.png'])); img.SetMask(True); img.SetMaskColour(255,255,255); self.bg = wx.BitmapFromImage(img); self.SetSize(wx.Size(self.bg.GetWidth(),self.bg.GetHeight())); self.hasShape = False; self.OnWindowCreate(); self.Bind(wx.EVT_RIGHT_UP,self.OnRightClickEvent); self.Bind(wx.EVT_WINDOW_CREATE,self.OnWindowCreate); self.Bind(wx.EVT_LEFT_DOWN,self.OnLeftClickDown); self.Bind(wx.EVT_LEFT_UP,self.OnLeftClickUp); self.Bind(wx.EVT_MOTION,self.OnMouseMotion); self.Bind(wx.EVT_PAINT,self.OnPaint); def OnRightClickEvent(self,event): if wx.MessageBox("是否退出程序?","退出",wx.YES_NO,self) == 2: wx.Exit(); def OnLeftClickDown(self,event): self.CaptureMouse(); pos = event.GetPosition(); self.pt = wx.Point(pos.x,pos.y); def OnMouseMotion(self,event): if event.Dragging() and event.LeftIsDown(): pos = self.ClientToScreen(event.GetPosition()); self.Move((pos.x-self.pt.x,pos.y-self.pt.y)); def OnLeftClickUp(self,event): if self.HasCapture(): self.ReleaseMouse(); def OnWindowCreate(self,event=None): r = wx.RegionFromBitmap(self.bg); self.SetShape(r); def OnPaint(self,event): dc = wx.PaintDC(self); dc.DrawBitmap(self.bg,0,0,True);class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(); self.frame.Show(True); self.SetTopWindow(self.frame); return True;if __name__ == "__main__": app = MyApp(); app.MainLoop();#该片段来自于http://byrx.net
评论关闭