Whenever I try the following in my python interpreter. I am able to copy the word hello to the command line, even after I close the interpreter
from Tkinter import Tk
r = Tk()
r.clipboard_append(" hello ")
However if I put this in a file called test.py and then try
python test.py
This will not work, I can't append this to the system clipboard
Does any one know why not or know what difference between running it in a script and in the interpreter would cause
Apparently it won't work until Tkinter is in it's mainloop. This works on my system:
from Tkinter import *
r = Tk()
r.clipboard_append("hello")
r.mainloop()
I see this difference in behavior too. The suggested tkinter solution for placing text on the clipboard works fine via the command line, but leaves the clipboard empty when used in a program. Using mainloop() at the end of the program works but means the program won't end, and using r.update() doesn't seem to help.
Note: If the clipboard is pasted to another application before the program ends (by making the program hang at the end waiting for user input), then the tkinter solution works fine, even after the program ends. But if the program ends before the clipboard is pasted to another program, the clipboard ends up being empty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With