How to get content with format from clipboard

限于喜欢 提交于 2019-12-01 07:19:57

问题


guys.

When i copy some words from internet using Chrome and paste to the Office Words, Words remind me that I can paste the words keeping source format.
That means clipboard can contain both the plain text and its format?

Meanwhile, I am writing an app using Python to get the content of clipboard. But don't know how to get the content format.

import Tkinter

if __name__ == '__main__':
    r=Tkinter.Tk()
    r.withdraw()
    print r.clipboard_get()
    r.destroy()

BTW, my app is running on Win7.

Thanks in advance. :)


回答1:


The clipboard does contain data in multiple formats. Typically, you've got TEXT/UnicodeText, RTF, and HTML.
See MSDN List of standard formats. and HTML Format.




回答2:


I suggest to don't write your own tool when there are existing modules doing the same. Try: http://coffeeghost.net/2010/10/09/pyperclip-a-cross-platform-clipboard-module-for-python/



来源:https://stackoverflow.com/questions/9630235/how-to-get-content-with-format-from-clipboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!