Getting data from the clipboard

Hi everyone,

I’m having trouble following the demo as it gets data from the clipboard. For my sake (I’m new to programming) I tried to write a very simple program to do this:

import wx
data = wx.TextDataObject
()
if wx.TheClipboard.Open():
success = wx.TheClipboard.GetData(data)
wx.TheClipboard.Close()
if success:
self.text.SetValue(data.GetText())
print data

But this doesn’t work. I get this error: “AttributeError: ‘NoneType’ object has no attribute ‘Open’” What am I doing wrong?

Thanks,
-Corey

It seems that for you, wx.TheClipboard is None. This is caused by the
fact that you haven't created a wx.App instance yet. Also, make sure to
'success=False' prior to trying to wx.TheClipboard.Open(), as if it
returns false, you won't get success assigned, and you would get a
NameError.

Try the following instead:

import wx

def foo():
    a = wx.App(0)
    success = False
    data = wx.TextDataObject()
    if wx.TheClipboard.Open():
        success = wx.TheClipboard.GetData(data)
        wx.TheClipboard.Close()
    if success:
        return data.GetText()
    return None

foo()

- Josiah

···

"cold wolf" <coldwolf9@gmail.com> wrote:

Hi everyone,

I'm having trouble following the demo as it gets data from the clipboard.
For my sake (I'm new to programming) I tried to write a very simple program
to do this:

import wx
data = wx.TextDataObject()
if wx.TheClipboard.Open():
    success = wx.TheClipboard.GetData(data)
    wx.TheClipboard.Close()
if success:
    self.text.SetValue(data.GetText())
    print data

But this doesn't work. I get this error: "AttributeError: 'NoneType' object
has no attribute 'Open'" What am I doing wrong?