- 静态文本显示:
# -*- coding: cp936 -*- # stxt.py """ stxt.py 2014/7/3 简单静态文本显示 """ import wx class StaticTextFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Static Text Example') #size=(400, 300)) panel = wx.Panel(self,-1) wx.StaticText(self,-1,"it is my first time using the StaticTextCtrl",pos=(10,20)) def main(): app=wx.App() Frame=StaticTextFrame() Frame.SetBackgroundColour("white") #设置背景颜色 Frame.Show() app.MainLoop() if __name__=="__main__": main()
wxStaticText::wxStaticText (parent, id, label, pos = wxDefaultPosition
, size = wxDefaultSize
, style = 0
, name = wxStaticTextNameStr
)
parent:父窗口部件。
id:标识符。使用-1或wx.ID_ANY可以自动创建一个唯一的标识。
label:你想显示在静态控件中的文本。
pos:一个wx.Point或一个Python元组,它是窗口部件的位置。
size:一个wx.Size或一个Python元组,它是窗口部件的尺寸。
style:样式标记。
name:对象的名字,用于查找的需要。
Styles:
This class supports the following styles:支持以下几种类型:
- wxALIGN_LEFT:左对齐
- wxALIGN_RIGHT: 右对齐
- wxALIGN_CENTRE_HORIZONTAL: 居中
- wxST_NO_AUTORESIZE:
By default, the control will adjust its size to exactly fit to the size of the text when SetLabel() is called. If this style flag is given, the control will not change its size (this style is especially useful with controls which also have the
wxALIGN_RIGHT
or thewxALIGN_CENTRE_HORIZONTAL
style because otherwise they won't make sense any longer after a call to SetLabel()). 默认设置,当SetLabel调用时,控件就会自动调整大小适应文本。如果指定这种类型,控件就不会改变他的大小(当指定wxALIGN_RIGHT或
wxALIGN_CENTRE_HORIZONTAL
时,就会非常有用,因为否则的话调用SetLabel后就没有意义了) - wxST_ELLIPSIZE_START:
If the labeltext width exceeds the control width, replace the beginning of the label with an ellipsis;若文本长度超出了控件宽度,那么文本开头就用省略号代替
- wxST_ELLIPSIZE_MIDDLE:
If the label text width exceeds the control width, replace the middle of the label with an ellipsis; 若文本长度超出了控件宽度,那么文本中间就用省略号代替
- wxST_ELLIPSIZE_END:
-
If the label text width exceeds the control width, replace the end of the label with an ellipsis; 若文本长度超出了控件宽度,那么文本尾部就用省略号代替
如下参见各种样式:
代码:
1 # -*- coding: cp936 -*- 2 # stxt.py 3 4 """ 5 stxt.py 2014/7/3 简单静态文本显示 6 """ 7 8 import wx 9 10 class StaticTextFrame(wx.Frame): 11 def __init__(self): 12 wx.Frame.__init__(self, None, -1, 'Static Text Example',size=(400, 800)) 13 14 panel = wx.Panel(self,-1) 15 16 self.textlabel = [#"import wx", 17 #"class StaticTextFrame(wx.Frame):", 18 #"def __init__(self):", 19 "wx.Frame.__init__(self, None, -1, 'Static Text Example',size=(400, 300))", 20 "panel = wx.Panel(self,-1)"] 21 styles = {"默认样式":0, 22 "wxALIGN_LEFT":wx.ALIGN_LEFT, 23 "wxALIGN_RIGHT":wx.ALIGN_RIGHT, 24 "wxALIGN_CENTRE_HORIZONTAL":wx.ALIGN_CENTRE_HORIZONTAL, 25 "wxST_NO_AUTORESIZE":wx.ST_NO_AUTORESIZE, 26 "wxST_ELLIPSIZE_START":wx.ST_ELLIPSIZE_START, 27 "wxST_ELLIPSIZE_MIDDLE":wx.ST_ELLIPSIZE_MIDDLE, 28 "wxST_ELLIPSIZE_END":wx.ST_ELLIPSIZE_END} 29 i=0 30 for stylename in styles.keys(): 31 st = wx.StaticText(self,-1,stylename,pos=(10,20+i*30)) 32 st.SetForegroundColour("blue") 33 for tb in self.textlabel: 34 i=i+1 35 wx.StaticText(self,-1,tb,pos=(10,20+i*30),style=0 | styles[stylename],size=(300,30)) 36 i=i+1 37 38 39 40 41 def main(): 42 app=wx.App() 43 Frame=StaticTextFrame() 44 Frame.SetBackgroundColour("white") #设置背景颜色 45 Frame.Show() 46 app.MainLoop() 47 48 if __name__=="__main__": 49 main() 50 51