我有一个奇怪的问题。我只能复制一次文本。如果我按清除并再次键入文本消失,我必须重新启动它。我搞砸了哪里?
现在问题:
1)我可以将clear函数绑定到“Encrypt / Decrypt”,这样每次我想再次输入它 自动清除?
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()
答案 0 :(得分:0)
每次按下按钮(方法option1
),都会创建新重叠的TextCtrl。您应该在构造函数中创建,只需更改方法中的文本。
1)只需在self.output.Clear()
方法的开头调用option1
。
2)
clipdata = wx.TextDataObject()
clipdata.SetText("Text here")
wx.TheClipboard.Open()
wx.TheClipboard.SetData(clipdata)
wx.TheClipboard.Close()