2011-11-02 9 views
0

私は奇妙な問題があります。私は一度だけテキストをコピーすることができます。クリアを押してもう一度入力すると、テキストが消えて再起動する必要があります。私はどこを台無しにしましたか?Wxpython - TextCtrl質問/奇妙なコピー "バグ"(?)

は今の質問:私はそれを再度入力するたびに が自動的にクリアされるように

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() 

答えて

0

ボタンを押すたびに(法option1)あなたは新しい重なり合うTextCtrlを作成します。コンストラクタで作成し、メソッド内のテキストを変更するだけです。

1)option1メソッドの冒頭でself.output.Clear()に電話するだけです。

2)私は最初から、このいずれかを開始しますので

clipdata = wx.TextDataObject() 
clipdata.SetText("Text here") 
wx.TheClipboard.Open() 
wx.TheClipboard.SetData(clipdata) 
wx.TheClipboard.Close() 
+0

は、これまでのところ、私は唯一の小さな別々の部品を作成しています。 (今回は少し頭がいっぱいです) ありがとうございました。 –