1

我想锁定我的 wx.stc.StyledTextCtrl 并且不允许写入它。有人知道可以做到这一点的功能吗?类似于 messagetxt.Lock() 另外,我想在 ReadOnly 中的代码中添加插入点的文本

import wx
from wx.stc import StyledTextCtrl`

app = wx.App()
frame = wx.Frame(None, -1, title='2', pos=(0, 0), size=(500, 500))
frame.Show(True)
messageTxt = StyledTextCtrl(frame, id=wx.ID_ANY, pos=(0, 0), size=(100 * 3, 100),
                            style=wx.TE_MULTILINE, name="File")
app.SetTopWindow(frame)
app.MainLoop()
4

1 回答 1

1

使用SetReadOnly(True)是一种方式,
如:

import wx
from wx.stc import StyledTextCtrl

app = wx.App()
frame = wx.Frame(None, -1, title='2', pos=(0, 0), size=(500, 500))
frame.Show(True)
messageTxt = StyledTextCtrl(frame, id=wx.ID_ANY, pos=(0, 0), size=(100 * 3, 100), style=wx.TE_MULTILINE, name="File")
messageTxt.SetText("This styled text is read only")
messageTxt.SetReadOnly(True)
app.SetTopWindow(frame)
app.MainLoop()

编辑:切换SetReadOnly标志将允许程序更改文本,而不是用户。
IE:

import wx
from wx.stc import StyledTextCtrl

class MyFrame(wx.Frame):
    def __init__(self, parent, id=wx.ID_ANY, title="", pos=wx.DefaultPosition, size=(400,500), style=wx.DEFAULT_FRAME_STYLE, name="MyFrame"):
        super(MyFrame, self).__init__(parent, id, title, pos, size, style, name)

        self.messageTxt = StyledTextCtrl(self, id=wx.ID_ANY, pos=(10,10), size=(300,100), style=wx.TE_MULTILINE)
        self.messageTxt.SetText("This styled text is read only")
        self.messageTxt.SetReadOnly(True)
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.onTimer, self.timer)
        self.timer.StartOnce(5000)


    def onTimer(self, event):
        print("timer")
        self.messageTxt.SetReadOnly(False)
        self.messageTxt.AppendText("\nThis styled text was briefly read only")
        self.messageTxt.AppendText("\nNow it's read only again!")
        self.messageTxt.SetReadOnly(True)

app = wx.App()
frame = MyFrame(None, title="The Main Frame")
frame.Show(True)
app.MainLoop()
于 2019-11-19T18:21:52.310 回答