繁体   English   中英

wxPython几何问题

[英]wxPython Geometry problem

我正在尝试使按钮位于标签的右边。 我设置了元组,但仍不确定为什么它覆盖了标签。

还有关于wxpython几何的很好的教程吗?

import wx
import wx.lib.agw.gradientbutton as GB

def GetRoundBitmap( w, h, r ):
    maskColor = wx.Color(0,0,0)
    shownColor = wx.Color(5,5,5)
    b = wx.EmptyBitmap(w,h)
    dc = wx.MemoryDC(b)
    dc.SetBrush(wx.Brush(maskColor))
    dc.DrawRectangle(0,0,w,h)
    dc.SetBrush(wx.Brush(shownColor))
    dc.SetPen(wx.Pen(shownColor))
    dc.DrawRoundedRectangle(0,0,w,h,r)
    dc.SelectObject(wx.NullBitmap)
    b.SetMaskColour(maskColor)
    return b

def GetRoundShape( w, h, r ):
    return wx.RegionFromBitmap( GetRoundBitmap(w,h,r) )

class FancyFrame(wx.Frame):
    def __init__(self):
        style = ( wx.CLIP_CHILDREN | wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR |
              wx.NO_BORDER | wx.FRAME_SHAPED  )
        wx.Frame.__init__(self, None, title='Fancy', style = style)
        self.SetSize( (250, 40) )
        self.SetPosition( (500,500) )
        self.SetTransparent( 160 )

        self.Bind(wx.EVT_KEY_UP, self.On_Esc)
        self.Bind(wx.EVT_MOTION, self.OnMouse)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        if wx.Platform == '__WXGTK__':
            self.Bind(wx.EVT_WINDOW_CREATE, self.SetRoundShape)
        else:
            self.SetRoundShape()

        self.Show(True)

        geo = wx.GridBagSizer()
        self.label = wx.StaticText(self,-1,label=u'Hello !')
        self.label.SetBackgroundColour("#000000")
        self.label.SetForegroundColour(wx.WHITE)
        self.label.SetSize( (50, 10) )
        geo.Add(self.label, (0,0))


        self.button = GB.GradientButton(self,label="button")
        self.label.SetBackgroundColour("#9e9e9e")
        geo.Add(self.button, (0,1))

    def SetRoundShape(self, event=None):
        w, h = self.GetSizeTuple()
        self.SetShape(GetRoundShape( w,h, 10 ) )


    def OnPaint(self, event):
        dc = wx.PaintDC(self)
        dc = wx.GCDC(dc)
        w, h = self.GetSizeTuple()
        r = 10
        dc.SetPen( wx.Pen("#000000", width = 4 ) )
        dc.SetBrush( wx.Brush("#9e9e9e") )
        dc.DrawRoundedRectangle( 0,0,w,h,r )

    def On_Esc(self, event):
        """quit if user press Esc"""
        if event.GetKeyCode() == 27 : #27 is Esc
            self.Close(force=True)
        else:
            event.Skip()

     def OnMouse(self, event):
        """implement dragging"""
        if not event.Dragging():
            self._dragPos = None
            return
        self.CaptureMouse()
        if not self._dragPos:
            self._dragPos = event.GetPosition()
        else:
            pos = event.GetPosition()
            displacement = self._dragPos - pos
            self.SetPosition( self.GetPosition() - displacement )



app = wx.App()
f = FancyFrame()
app.MainLoop()

您忘记将FancyFrame设置为具有给定的布局大小。

换句话说,您需要在FancyFrame__init__方法的末尾添加一行。

self.SetSizerAndFit(geo)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM