wxpython add line to TextCtrl

强颜欢笑 提交于 2019-12-19 22:35:55

问题


I have a multi line, read only TextCtrl in wxpython I know how to set values using

myTextCtrl.SetValue('hello')

But this will change whatever I previously had in my TextCtrl... How do I add a new line and keep whatever I had before?


回答1:


Either widget.AppendText or widget.WriteText will write a new line each time if you send your string with a newline character (like 'hello\n')

AppendText, would append the text at the end of the text in the control. WriteText is the same except because the new text in placed at the current insertion point.




回答2:


I've had issues like this before and want to share what I discovered on this topic for future inquiries.

In order to successfully have a multiline widget.TextCtrl object that interprets newline (\n) characters properly, two conditions have to be met:

1) The wx.TE_MULTILINE tag is included in the "style" argument when instantiating the object.

2) When setting the text value of the widget.TextCtrl object, you must use widget.SetValue and not widget.SetLabel to properly include the newline character. Using widget.SetLabel removes the newline characters entirely, and possibly other non-printable characters as well.




回答3:


myTextCtrl.AppendText('hello')

This does not add a newline character on its own, so you will have to include that in the string if needed.



来源:https://stackoverflow.com/questions/5250593/wxpython-add-line-to-textctrl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!