How do I copy a string to the clipboard on Windows using Python?

后端 未结 23 2805
温柔的废话
温柔的废话 2020-11-22 03:13

I\'m trying to make a basic Windows application that builds a string out of user input and then adds it to the clipboard. How do I copy a string to the clipboard using Pytho

23条回答
  •  情歌与酒
    2020-11-22 03:47

    import wx
    
    def ctc(text):
    
        if not wx.TheClipboard.IsOpened():
            wx.TheClipboard.Open()
            data = wx.TextDataObject()
            data.SetText(text)
            wx.TheClipboard.SetData(data)
        wx.TheClipboard.Close()
    
    ctc(text)
    

提交回复
热议问题