脚本专栏 
首页 > 脚本专栏 > 浏览文章

wxpython绘制圆角窗体

(编辑:jimmy 日期: 2024/11/20 浏览:3 次 )

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:解决pandas展示数据输出时列名不能对齐的问题
下一篇:python 实现绘制整齐的表格
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap