Manipulating data in the clipboard

While you have the clipboard open, you can manipulate the data object it holds in a couple of different ways. You can place your object on the clipboard with Set-Data(data), where the data parameter is any wx.DataObject instance. You can empty the clipboard with the method Clear(). If you want the data on the clipboard to survive after the close of your application, you must call the method Flush(), which instructs the system to hold on to your data. Otherwise, the wxPython clipboard object is cleared when your application exits.

Here is the code to add text to the clipboard:

text_data = wx.TextDataObject("hi there")

if wx.TheClipboard.Open():

wx.TheClipboard.SetData(text_data) wx.TheClipboard.Close()

Was this article helpful?

0 0

Post a comment