我希望文本框自动删除以前的输出,这样我就可以键入一个完整的句子,而不必将每个字母打印到文本框。但是,它会一直重复,所以当我按下保存按钮时,它会将每一行记录到剪贴板中。你知道吗
我尝试过使用Tkinter文本删除:文本.删除(1.0,结束)。但是,它不会删除任何内容。你知道吗
class ExamplePanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, size=(3000,2000))
self.cipherText = wx.StaticText(self, label="Ciphered Text: ", pos=(20, 30))
#A multiline TextCtrl- Shows the events in the program.
#I think this might be where the problem is but I do not know how to
#get it to only print once, perhaps after the user hits "enter" or something.
self.logger = wx.TextCtrl(self, pos=(300,20), size=(200,300), style=wx.TE_MULTILINE | wx.TE_READONLY)
self.encrypt = wx.StaticText(self, label="Encryptor: ", pos=(20,60))
self.encryptEdit = wx.TextCtrl(self, value="", pos=(150, 60), size=(140,-1))
self.Bind(wx.EVT_TEXT, self.EncText, self.encryptEdit)
self.Bind(wx.EVT_CHAR, self.EncChar, self.encryptEdit)
def EncText(self,event):
result = ''
message = event.GetString()
for i in range(0, len(message)):
result = result + chr(ord(message[i]) - 2)
result = result.replace(chr(30), ' ')
print(result + '\n\n')
self.logger.AppendText(result + '\n\n')
如上所述,我的目标是每当有新的击键时清空文本框,这样就不会一直重复下去。这就是它现在的样子:Current Output
而不是
.ApppendText(result + '\n\n')
尝试.SetValue(result + '\n\n')
。它应该替换TextCtrl
中的文本见文件wx.TextCtrl。
wx.TextCtrl
基于wx.TextEntry
,因此TextCtrl
的一些函数可以在wx.TextEntry的文档中找到。还有SetValue()
。你知道吗相关问题 更多 >
编程相关推荐