Wxpython - TextCtrl 问题/奇怪的复制“bug” (?)
我有一个奇怪的问题。我只能将文本复制一次。如果我按清除并再次输入,文本就会消失,我必须重新启动它。我哪里搞砸了?
现在的问题是:
1)我可以将清除功能绑定到“加密/解密”,以便每次我想再次输入它吗 自动清除?
2)如何使用按钮将输出复制到剪贴板?
代码(相当混乱):
import wx
class main(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Title',size=(353,270))
self.panel=wx.Panel(self)
button1=wx.Button(self.panel,label='Encrypt\Decrypt',pos=(10,10),size=(-1,60))
button2=wx.Button(self.panel,label='Current PIN', pos=(150,10),size=(-1,60))
button3=wx.Button(self.panel,label='Change PIN', pos=(250,10),size=(-1,60))
button4= wx.Button(self.panel,label='Reset',pos=(10,200),size=(-1,20))
self.Bind(wx.EVT_BUTTON, self.option1, button1)
self.Bind(wx.EVT_BUTTON, self.option2, button2)
self.Bind(wx.EVT_BUTTON, self.option3, button3)
self.Bind(wx.EVT_BUTTON, self.clear, button4)
self.Bind(wx.EVT_CLOSE,self.closewindow)
self.pin='ABC'
def option1(self,event):
box1=wx.TextEntryDialog(None,'Type...','','...here')
if box1.ShowModal()==wx.ID_OK:
answer1=box1.GetValue()
def xor(text, key):
list = ''
for char in text:
for ch in key:
char = chr(ord(char) ^ ord(ch))
list += char
return list
msg = xor(answer1, self.pin)
self.output=wx.TextCtrl(self.panel, -1,msg,pos=(10,80),size=(300, 100), style=wx.TE_MULTILINE|wx.TE_READONLY)
#output=wx.StaticText(self.panel,-1,msg,(10,80),(260,-1),wx.ALIGN_CENTER)
def option2(self,event):
box2=wx.MessageDialog(None,self.pin,'Current PIN',wx.OK)
answer2=box2.ShowModal()
box2.Destroy()
def option3(self,event):
box3=wx.TextEntryDialog(None,'Type...','','...here')
if box3.ShowModal()==wx.ID_OK:
answer3=box3.GetValue()
self.pin=answer3
def closewindow(self,event):
self.Destroy()
def clear(self,event):
self.output.Clear()
if __name__=='__main__':
app=wx.PySimpleApp()
frame=main(parent=None,id=-1)
frame.Show()
app.MainLoop()
I have a weird problem. I can only copy the text once. If I press clear and type again the text disappears and I have to restart it. Where have I messed up?
Now the questions:
1) Can I bind the clear function to the "Encrypt/Decrypt" so that each time I want to type again it
clears automatically?
2)How can I copy the output to the clipboard with a button?
Code(Pretty messy):
import wx
class main(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Title',size=(353,270))
self.panel=wx.Panel(self)
button1=wx.Button(self.panel,label='Encrypt\Decrypt',pos=(10,10),size=(-1,60))
button2=wx.Button(self.panel,label='Current PIN', pos=(150,10),size=(-1,60))
button3=wx.Button(self.panel,label='Change PIN', pos=(250,10),size=(-1,60))
button4= wx.Button(self.panel,label='Reset',pos=(10,200),size=(-1,20))
self.Bind(wx.EVT_BUTTON, self.option1, button1)
self.Bind(wx.EVT_BUTTON, self.option2, button2)
self.Bind(wx.EVT_BUTTON, self.option3, button3)
self.Bind(wx.EVT_BUTTON, self.clear, button4)
self.Bind(wx.EVT_CLOSE,self.closewindow)
self.pin='ABC'
def option1(self,event):
box1=wx.TextEntryDialog(None,'Type...','','...here')
if box1.ShowModal()==wx.ID_OK:
answer1=box1.GetValue()
def xor(text, key):
list = ''
for char in text:
for ch in key:
char = chr(ord(char) ^ ord(ch))
list += char
return list
msg = xor(answer1, self.pin)
self.output=wx.TextCtrl(self.panel, -1,msg,pos=(10,80),size=(300, 100), style=wx.TE_MULTILINE|wx.TE_READONLY)
#output=wx.StaticText(self.panel,-1,msg,(10,80),(260,-1),wx.ALIGN_CENTER)
def option2(self,event):
box2=wx.MessageDialog(None,self.pin,'Current PIN',wx.OK)
answer2=box2.ShowModal()
box2.Destroy()
def option3(self,event):
box3=wx.TextEntryDialog(None,'Type...','','...here')
if box3.ShowModal()==wx.ID_OK:
answer3=box3.GetValue()
self.pin=answer3
def closewindow(self,event):
self.Destroy()
def clear(self,event):
self.output.Clear()
if __name__=='__main__':
app=wx.PySimpleApp()
frame=main(parent=None,id=-1)
frame.Show()
app.MainLoop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每次按下按钮(方法
option1
)时,您都会创建一个新重叠的TextCtrl。您应该在构造函数中创建并仅更改方法中的文本。1) 只需在
option1
方法的开头调用self.output.Clear()
即可。2)
Every time you push the button (method
option1
) you create a new overlapping TextCtrl. You should have created in the constructor and just change the text in the method.1) Just call
self.output.Clear()
at the beginning of theoption1
method.2)