This article gives an example of how Wxpython uses the system Clipboard. Share to everyone for your reference. Specifically as follows:
The program works as shown in the following illustration:
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 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. Theclipboard.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. Theclipboard.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 your Python programming.