Tuesday 31 August 2021

tkinter "scrolledtext" copy paste doesn't work reliably

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

enter image description here



from tkinter "scrolledtext" copy paste doesn't work reliably

No comments:

Post a Comment