I have found a behaviour which seems to be a bug in tkinter
.
If you run the following (minimal to reproduce the bug) code:
import tkinter, tkinter.simpledialog, tkinter.scrolledtext
root = tkinter.Tk('test')
text = tkinter.scrolledtext.ScrolledText(master=root, wrap='none')
text.pack(side="top", fill="both", expand=True, padx=0, pady=0)
text.insert(tkinter.END, 'abc\ndef\nghi\nijk')
root.mainloop()
then:
- select one row in the
scrolledtext
widget, e.g. the row "ghi", - copy it with CTRL+C
- do nothing else and close the app
Then paste it (CTRL+V) in any other Windows app: it won't work, nothing will be pasted. Why?
How to solve this?
Note: the expected behaviour is that text copied with CTRL+C should persist in the clipboard even if the app is closed. This is the default behaviour in many Windows software. Example here with notepad.exe
:
link to the animated screen capture: https://i.imgur.com/li7UvYw.mp4
Note: this is linked to
tkinter
window, all of the clipboard items thattkinter
added get deleted on my computer. Also what is the point oftext.focus()
? Did you meantext.focus_set()
?.focus()
part which was useless for this minimal example. More important: as an example, even ifnotepad.exe
is closed, any copied text will be kept even if notepad.exe is closed. Example: imgur.com/li7UvYw This is the expected behaviour. Here with tkinter, it does not work. Any idea how to solve this?tkinter
works. I know it's very annoying and don't know why it is that way. You can instead bind toControl-c
and use theclipboard
library to copy the data. That should actually copy the data to the clipboard even if thetkinter
window is closed.