在wxPython中,wx.StaticText類物件提供了一個控制元件持有這樣的唯讀文字。它被動控制,因為不產生任何事件。Wx.StaticText類別建構函式需要下列的引數-
Wx.StaticText(parent, id, label, position, size, style)
wx.ALIGN_LEFT |
控制標籤的大小及對齊
|
wx.ALIGN_RIGHT | |
wx.ALIGN_CENTER | |
wx.ST_NO_AUTORESIZE |
防止標籤的自動調整大小
|
wx.ST_ELLIPSIZE_START |
省略號(...)顯示在開始,中間或結尾,如果文字的大小大於標籤尺寸
|
wx.ST_ELLIPSIZE_MIDDLE | |
wx.ST_ELLIPSIZE_END |
所述第一物件中心對準多行文字。第二個標籤的文字設定為環繞超過200畫素。第三標籤顯示省略號(...)在文字的中間。
Wx.Font(pointsize, fontfamily, fontstyle, fontweight)
S.N. | 引數 & 描述 |
---|---|
1 |
Wx.FONTSTYLE_NORMAL
字型繪制不使用傾斜
|
2 |
wx.FONTSTYLE_ITALIC
字型是斜體
|
3 |
wx.FONTSTYLE_SLANT
字型是傾斜的,但以羅馬風格形式
|
S.N. | 引數 & 描述 |
---|---|
1 |
Wx.FONTWEIGHT_NORMAL
普通字型
|
2 |
wx.FONTWEIGHT_LIGHT
高亮字型
|
3 |
wx.FONTWEIGHT_BOLD
粗體
|
import wx class Mywin(wx.Frame): def __init__(self, parent, title): super(Mywin, self).__init__(parent, title = title,size = (600,200)) panel = wx.Panel(self) box = wx.BoxSizer(wx.VERTICAL) lbl = wx.StaticText(panel,-1,style = wx.ALIGN_CENTER) txt1 = "Python GUI development" txt2 = "using wxPython" txt3 = " Python port of wxWidget " txt = txt1+"\n"+txt2+"\n"+txt3 font = wx.Font(18, wx.ROMAN, wx.ITALIC, wx.NORMAL) lbl.SetFont(font) lbl.SetLabel(txt) box.Add(lbl,0,wx.ALIGN_CENTER) lblwrap = wx.StaticText(panel,-1,style = wx.ALIGN_RIGHT) txt = txt1+txt2+txt3 lblwrap.SetLabel(txt) lblwrap.Wrap(200) box.Add(lblwrap,0,wx.ALIGN_LEFT) lbl1 = wx.StaticText(panel,-1, style = wx.ALIGN_LEFT | wx.ST_ELLIPSIZE_MIDDLE) lbl1.SetLabel(txt) lbl1.SetForegroundColour((255,0,0)) lbl1.SetBackgroundColour((0,0,0)) font = self.GetFont() font.SetTutorialsSize(20) lbl1.SetFont(font) box.Add(lbl1,0,wx.ALIGN_LEFT) panel.SetSizer(box) self.Centre() self.Show() app = wx.App() Mywin(None, 'StaticText demo') app.MainLoop()