I want to access the filename copied in Windows Explorer (or some other file manager) in my tkinter program. Here's how I'm trying to do this:
from tkinter import *
root = Tk()
def print_filename():
print(root.clipboard_get(type="FILE_NAME"))
but = Button(root, text="Show filename", command=print_filename)
but.grid()
root.mainloop()
Unfortunately I get same error both in Windows 7/Python 3.4.1 and in Lubuntu 13.10/Python 3.3.2:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1487, in __call__
return self.func(*args)
File "C:\Users\Aivar\Desktop\get_file_from_clipboard.py", line 6, in show_filename
print(root.clipboard_get(type="FILE_NAME"))
File "C:\Python34\lib\tkinter\__init__.py", line 587, in clipboard_get
return self.tk.call(('clipboard', 'get') + self._options(kw))
_tkinter.TclError: CLIPBOARD selection doesn't exist or form "FILE_NAME" not defined
Am I doing something wrong or should I report this as a bug?