platform-independent image copy/paste with Tkinter?

T

technocake

Hi.

Is there a good way to copy from or paste to the clipboard on all
systems running python using Tkinter?
started a small road too it here:

#!/usr/bin/python
__author__="technocake"
__date__ ="$15.mai.2010 15:53:39$"

from Tkinter import *

if __name__ == "__main__":

def displayClipboard(event):
try:
data = event.widget.clipboard_get(type="STRING")
except :
#Need a method for displaying a image here..
data = "Image" #
finally: #Updates the textlabel
lbl.config(text=data)

root = Tk()
lbl= Label(root, width=20)
lbl.bind("<Button-1>", displayClipboard) #binding to leftclick
lbl.pack()

root.mainloop()
 
E

eb303

Hi.

Is there a good way to copy from or paste to the clipboard on all
systems running python using Tkinter?
started a small road too it here:

#!/usr/bin/python
__author__="technocake"
__date__ ="$15.mai.2010 15:53:39$"

from Tkinter import *

if __name__ == "__main__":

    def displayClipboard(event):
        try:
            data = event.widget.clipboard_get(type="STRING")
        except :
            #Need a method for displaying a image here..
            data = "Image" #
        finally: #Updates the textlabel
            lbl.config(text=data)

    root = Tk()
    lbl= Label(root, width=20)
    lbl.bind("<Button-1>", displayClipboard) #binding to leftclick
    lbl.pack()

    root.mainloop()

The copy part is done via the methods clipboard_clear and
clipboard_append, available on all Tkinter widgets. By the way, the
default value for the 'type' option is 'STRING', so you actually don't
need it here, and neither do you in clipboard_append.

To be able to copy/paste images is much more platform dependent. There
are actually types for clipboard contents that handle images, but they
will vary from platform to platform and sometimes from application to
application. You can even have several types for the same contents. To
get these, you can use:
widget.selection_get(selection='CLIPBOARD', type='TARGETS')
You can try to copy an image on various platforms with various
applications, then print the value for this expression to figure out
what you can do with it.

HTH
- Eric -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top