Related to the development of desktop programs, especially text processing, the Clipboard is very common, not like in Java so annoying lock, wxpython access to the Clipboard is very simple, a few sentences enough.
# Get the Clipboard and make sure it is open text_obj = wx. Textdataobject () wx. Theclipboard.open () if wx. Theclipboard.isopened () or WX. Theclipboard.open (): # do something ... Wx. Theclipboard.close ()
Value:
If WX. Theclipboard.getdata (text_obj): text = text_obj. GetText ()
Write Value:
Text_obj. SetText (' The value to write ') wx. Theclipboard.setdata (Text_obj)
In the following example, clicking Copy Copies the values in the text box to the Clipboard, and clicking Paste will paste the text from the Clipboard into the text box.
"" "Get text from and put text on the Clipboard." " Import Wxclass myframe (WX. Frame): def __init__ (self): WX. Frame.__init__ (self, None, title= ' Accessing the Clipboard ', size= (+)) # components Self.panel = WX. Panel (self) self.text = wx. Textctrl (Self.panel, pos= (Ten), size= (370)) Self.copy = WX. Button (Self.panel, Wx.id_any, label= ' Copy ', pos= (ten)) Self.paste = WX. Button (Self.panel, Wx.id_any, label= ' Paste ', pos= (+)) # Event bindings. Self. Bind (WX. Evt_button, self. Oncopy, self.copy) self. Bind (WX. Evt_button, self. Onpaste, Self.paste) def oncopy (Self, event): Text_obj = wx. Textdataobject () text_obj. SetText (Self.text.GetValue ()) if wx. Theclipboard.isopened () or WX. Theclipboard.open (): WX. Theclipboard.setdata (text_obj) wx. Theclipboard.close () def onpaste (Self, event): Text_obj = wx. Textdataobject () if wx. Theclipboard.isopened () or WX. Theclipboard.open (): If WX. Theclipboard.getdata (text_obj): Self.text.SetValue (text_obj. GetText ()) wx. Theclipboard.close () app = WX. APP (False) frame = MyFrame () frame. Show (True) app. Mainloop ()