wxpython核心部件wx.statictext入门教程

发布时间:2019-12-30编辑:脚本学堂
有关wxpython核心部修的wx.statictext的用法,wx.StaticText 部件显示一行或多行的只读文本,通过例子学习下这个wxpython部件的用法。

专题教程:wxpython中文教程

wx.StaticText 部件显示一行或多行的只读文本.

wxpython核心部件

wx.StaticText 的样式有:
 

wx.ALIGN_RIGHT
wx.ALIGN_LEFT
wx.ALIGN_CENTER / wx.ALIGN_CENTRE
wx.ST_NO_AUTORESIZE

如图:
wxpython核心部件wx.statictext
wx.statictext.methods

例子:
 

复制代码 代码示例:

#!/usr/bin/python
#coding=utf-8
#statictext.py
# www.plcxue.com

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,
       wx.Size(400, 350))
       
        lyrics1 = '''I'm giving up the ghost of love
        in the shadows cast on devotion
        She is the one that I adore
        creed of my silent suffocation
        break this bittersweet spell on me
        lost in the arms of destiny'''

        lyrics2 = '''There is something in the way
        You're always somewhere else
        Feelings have deserted me
        To a point of no return
        I don't believe in God
        But I pray for you'''
       
        panel = wx.Panel(self, -1)
        wx.StaticText(panel, -1, lyrics1, (45, 25), style=wx.ALIGN_LEFT)
        wx.StaticText(panel, -1, lyrics2, (45, 190), style=wx.ALIGN_CENTER)
       
        self.Center()
       
class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'statictext.py')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True
   
app = MyApp(0)
app.MainLoop()

如图:
wxpython核心部件wx.statictext
图:statictext.py