标签中的溢出文本

时间:2016-03-04 01:58:14

标签: python wxpython

我有这段代码

import wx, time

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.SetBackgroundColour(wx.BLACK)
        self.SetTransparent( 150 )

        self.panel = wx.Panel(self)     
        self.lblname = wx.StaticText(self.panel, label="Your name aaaa:")
        #self.lblname.Wrap(210)


        self.lblname.SetForegroundColour((91,91,91)) # set text color

        self.sizer = wx.GridBagSizer(500, 500)
        self.sizer.Add(self.lblname, (1, 0))


        if wx.Platform == '__WXGTK__':
            self.Bind(wx.EVT_WINDOW_CREATE, self.SetRoundShape)
        else:
            self.SetRoundShape()

        self.Show(True)

    def SetRoundShape(self, event=None):
        w, h = self.GetSizeTuple()
        w=250
        h=50
        self.SetShape(GetRoundShape( w,h, 10 ) )
        dw, dh = wx.DisplaySize()
        #w, h = self.GetSize()
        x = dw - w
        x = (dw/2) - (w/2)
        y = dh - h - 50
        self.SetPosition((x, y))


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

我需要"你的名字aaaa:"与中心对齐,但我不知道为什么它会被切断。怎么解决?

1 个答案:

答案 0 :(得分:0)

你的网袋有点过了,你没有设置尺寸 尝试:

self.sizer = wx.GridBagSizer(1,1)
self.sizer.Add(self.lblname,pos=(1,2),flag=wx.ALIGN_CENTER)

和:

self.panel.SetSizer(self.sizer)
self.Show(True)