Tutorial on getting data from the system Clipboard using Wxpython

Source: Internet
Author: User
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 ()
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.