Tkinter: Copy to Clipboard on Widget Click
January 22, 2015
Problem
I recently implemented a cross-platform desktop GUI to continuously scrape a certain web application for new data and provide real time updates to the user when new data is available. Once new data is available, the customer transfers that record to another program, which per the terms & conditions they aren’t permitted to automate, so it has to be done manually. In this case, the time to highlight the contents of a field and copy it took precious seconds, so we implemented the following cross-platform solution in python using the Tkinter package that copies the entire field to the clipboard when a mouse clicks on the specific field (text widget).
Python Code
Closing remarks
The code above was extracted from a class specific to the customer use case, and by itself it’s not very useful, but should give an idea of concept. Also, there isn’t any visual feedback for the click to copy, so the user must be aware of that functionality.