https://www.cnblogs.com/ankier/archive/2012/09/17/2689364.html
wx.TextCtrl的构造函数
wx.TextCtrl(parent, id, value=‘‘, pos=wx.DefaultPostion, size=wx.DefaultSize, style=0, validator=wx.DefaultValidator, name=wx.TextCtrlNameStr)
---------------------------------------------------
parent:父窗口部件
id:标识符。使用-1可以自动创建一个唯一的标识。
value:显示的内容
pos:一个wx.Point或一个Python元组,它是窗口部件的位置。
size:一个wx.Size或一个Python元组,它是窗口部件的尺寸。
style:样式标记
validator:赋予textctrl的内容校验器
name:对象的名字,用于查找的需要。
---------------------------------------------------
其中基本样式的取值有:
#-------------------------------------------------------------------------------
# Name: TextCtrlExampleFrame
# Purpose:
#
# Author: ankier
#
# Created: 17/09/2012
# Copyright: (c) ankier 2012
# Licence: <your licence>
#-------------------------------------------------------------------------------
import wx
class TextCtrlExampleFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Text ctrl example", pos =(0,0), size =(800, 600))
panel = wx.Panel(self, -1)
#输入文本居中对齐
text = wx.TextCtrl(panel, wx.ID_ANY,pos=(0,30), size =(200, 20), style = wx.TE_CENTER)
#显示密码文本框
text = wx.TextCtrl(panel, wx.ID_ANY, pos=(0,60), size =(200, 20), style = wx.TE_PASSWORD)
#显示只读文本
text = wx.TextCtrl(panel, wx.ID_ANY, pos=(0,90), size =(200, 20), style = wx.TE_READONLY)
def main():
app = wx.PySimpleApp()
frame = TextCtrlExampleFrame()
frame.Show(True)
app.MainLoop()
if __name__ == ‘__main__‘:
main()
多行或丰富文本样式有
#-------------------------------------------------------------------------------
# Name: TextCtrlExampleFrame
# Purpose:
#
# Author: ankier
#
# Created: 17/09/2012
# Copyright: (c) ankier 2012
# Licence: <your licence>
#-------------------------------------------------------------------------------
import wx
class TextCtrlExampleFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Text ctrl example", pos =(0,0), size =(800, 600))
panel = wx.Panel(self, -1)
#多行文本样式
text = wx.TextCtrl(panel, wx.ID_ANY,pos=(0,70), size =(200, 60), style = wx.TE_MULTILINE)
#window下富文本
text = wx.TextCtrl(panel, wx.ID_ANY,pos=(0,140), size =(200, 60), style = wx.TE_RICH)
def main():
app = wx.PySimpleApp()
frame = TextCtrlExampleFrame()
frame.Show(True)
app.MainLoop()
if __name__ == ‘__main__‘:
main()
编程下改变文本内容方式有:
#-------------------------------------------------------------------------------
# Name: TextCtrlExampleFrame
# Purpose:
#
# Author: ankier
#
# Created: 17/09/2012
# Copyright: (c) ankier 2012
# Licence: <your licence>
#-------------------------------------------------------------------------------
import wx
class TextCtrlExampleFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Text ctrl example", pos =(0,0), size =(800, 600))
panel = wx.Panel(self, -1)
#多行文本样式
self.text = wx.TextCtrl(panel, wx.ID_ANY,pos=(70, 0), size =(200, 60), style = wx.TE_MULTILINE)
button = wx.Button(panel, wx.ID_ANY, pos = (210, 70), size =(100, 20), label = ‘Append‘)
button.Bind(wx.EVT_BUTTON, self.__OnAppendButtonClick)
button = wx.Button(panel, wx.ID_ANY, pos = (110, 70), size =(60, 20), label = ‘Clear‘)
button.Bind(wx.EVT_BUTTON, self.__OnClearClick)
def __OnAppendButtonClick(self, event):
self.text.AppendText("appended text")
def __OnClearClick(self, event):
self.text.Clear()
def main():
app = wx.PySimpleApp()
frame = TextCtrlExampleFrame()
frame.Show(True)
app.MainLoop()
if __name__ == ‘__main__‘:
main()
原文:https://www.cnblogs.com/Ian-learning/p/10055976.html