欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

wxpython绘制圆角窗体

时间:2021-02-05 09:28:52|栏目:Python代码|点击:

本文实例为大家分享了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()

上一篇:使用pyqt5 tablewidget 单元格设置正则表达式

栏    目:Python代码

下一篇:Windows上使用virtualenv搭建Python+Flask开发环境

本文标题:wxpython绘制圆角窗体

本文地址:http://www.codeinn.net/misctech/57248.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有