DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Get And Set Windows Clipboard

09.16.2005
| 30247 views |
  • submit to reddit
        From June Kim's <a href=http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/150115>recipe</a>.
import win32clipboard as w 
import win32con

def getText(): 
    w.OpenClipboard() 
    d=w.GetClipboardData(win32con.CF_TEXT) 
    w.CloseClipboard() 
    return d 
 
def setText(aType,aString): 
    w.OpenClipboard()
    w.EmptyClipboard()
    w.SetClipboardData(aType,aString) 
    w.CloseClipboard()
    

Comments

Snippets Manager replied on Tue, 2007/06/05 - 11:43am

Note that win32clipboard has the constant CF_TEXT, so no need to import win32con to use it. -Anonymous Coward