How to use the system clipboard in wxPython

Source: Internet
Author: User

How to use the system clipboard in wxPython

This article describes how wxPython uses the system clipboard. Share it with you for your reference. The details are as follows:

Shows the program running effect:

The main code is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

Import wx

######################################## ################################

Class ClipboardPanel (wx. Panel ):

""""""

#----------------------------------------------------------------------

Def _ init _ (self, parent ):

"" Constructor """

Wx. Panel. _ init _ (self, parent)

Lbl = wx. StaticText (self, label = "Enter text to copy to clipboard :")

Self. text = wx. TextCtrl (self, style = wx. TE_MULTILINE)

CopyBtn = wx. Button (self, label = "Copy ")

CopyBtn. Bind (wx. EVT_BUTTON, self. onCopy)

CopyFlushBtn = wx. Button (self, label = "Copy and Flush ")

CopyFlushBtn. Bind (wx. EVT_BUTTON, self. onCopyAndFlush)

Sizer = wx. BoxSizer (wx. VERTICAL)

Sizer. Add (lbl, 0, wx. ALL, 5)

Sizer. Add (self. text, 1, wx. EXPAND)

Sizer. Add (copyBtn, 0, wx. ALL | wx. CENTER, 5)

Sizer. Add (copyFlushBtn, 0, wx. ALL | wx. CENTER, 5)

Self. SetSizer (sizer)

#----------------------------------------------------------------------

Def onCopy (self, event ):

""""""

Self. dataObj = wx. TextDataObject ()

Self. dataObj. SetText (self. text. GetValue ())

If wx. thpolicboard. Open ():

Wx. TheClipboard. SetData (self. dataObj)

Wx. TheClipboard. Close ()

Else:

Wx. MessageBox ("Unable to open the clipboard", "Error ")

#----------------------------------------------------------------------

Def onCopyAndFlush (self, event ):

""""""

Self. dataObj = wx. TextDataObject ()

Self. dataObj. SetText (self. text. GetValue ())

If wx. thpolicboard. Open ():

Wx. TheClipboard. SetData (self. dataObj)

Wx. TheClipboard. Flush ()

Else:

Wx. MessageBox ("Unable to open the clipboard", "Error ")

Self. GetParent (). Close ()

######################################## ################################

Class ClipboardFrame (wx. Frame ):

""""""

#----------------------------------------------------------------------

Def _ init _ (self ):

"" Constructor """

Wx. Frame. _ init _ (self, None, title = "Clipboard Tutorial ")

Panel = ClipboardPanel (self)

Self. Show ()

If _ name _ = "_ main __":

App = wx. App (False)

Frame = ClipboardFrame ()

App. MainLoop ()

I hope this article will help you with Python programming.

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.