这篇文章将为大家详细讲解有关wxpython如何绘制圆角窗体,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
具体内容如下
# -*- coding:gbk -*- import wx class RCDialog(wx.Dialog): def __init__(self,parent=None,size=wx.DefaultSize): wx.Dialog.__init__(self, parent, -1, size=size, style=wx.FRAME_SHAPED | wx.SIMPLE_BORDER | wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP) self.Centre( wx.BOTH) # linux平台 if wx.Platform == "__WXGTK__": self.Bind(wx.EVT_WINDOW_CREATE, self.SetBalloonShape) else: self.SetBalloonShape() self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_MOTION, self.OnMouseMove) self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp) def OnLeftDown(self, event): pos = event.GetPosition() x, y = self.ClientToScreen(event.GetPosition()) ox, oy = self.GetPosition() dx = x - ox dy = y - oy self.delta = ((dx, dy)) def OnMouseMove(self, event): if event.Dragging() and event.LeftIsDown(): x, y = self.ClientToScreen(event.GetPosition()) fp = (x - self.delta[0], y - self.delta[1]) self.Move(fp) def OnRightUp(self, evt): self.Close() def SetBalloonShape(self, event=None): width, height = self.GetSize() bmp = wx.EmptyBitmap(width,height) dc = wx.BufferedDC(None, bmp) dc.BeginDrawing() dc.SetBackground(wx.Brush(wx.Colour(0,0,0), wx.SOLID)) dc.Clear() dc.DrawRoundedRectangle(0, 0, width-1, height-1, 4) dc.EndDrawing() r = wx.RegionFromBitmapColour(bmp, wx.Colour(0,0,0)) self.hasShape = self.SetShape(r) if __name__ == "__main__": app = wx.PySimpleApp() dlg = RCDialog(size=(376,282)) dlg.Show() app.MainLoop()
关于“wxpython如何绘制圆角窗体”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。