copy to clipboard

22 views
Skip to first unread message

thebikesh...@gmail.com

unread,
Dec 27, 2021, 11:27:59 PM12/27/21
to wxPython-users

probably been asked before, but I can't seem to find a solution, getting an error after repeatedly Ctrl-c using clipboard, pasted resulting message box into notepad and get

[Window Title]
Shop Error

[Content]
Failed to put data on the clipboard (error -2147221040: OpenClipboard Failed)

[OK]

also happens using the following example code 

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()

using Python 3.6.8
4.1.0 msw (phoenix) wxWidgets 3.1.4
windows 10


thanks in advance.

Johnny

Dietmar Schwertberger

unread,
Dec 28, 2021, 6:54:40 AM12/28/21
to wxpytho...@googlegroups.com
On 27.12.2021 23:14, thebikesh...@gmail.com wrote:
> also happens using the following example code

Your sample code has no line breaks. Either format it properly or attach
it to the post or maybe post it to https://discuss.wxpython.org/

Regards,

Dietmar


Reply all
Reply to author
Forward
0 new messages