def _setup_tkinter(self):
'''Creates a Tkinter input file dialog'''
# Import Tkinter GUI widgets
if sys.version_info.major == 2:
from tkFileDialog import askopenfilename, asksaveasfilename
import Tkinter as tk
else:
from tkinter.filedialog import askopenfilename, asksaveasfilename
import tkinter as tk
# Code below is to make sure the file dialog appears above the
# terminal/browser
# Based on
# http://stackoverflow.com/questions/3375227/how-to-give-tkinter-file-dialog-focus
# Make a top-level instance and hide since it is ugly and big.
root = tk.Tk()
root.withdraw()
# Make it almost invisible - no decorations, 0 size, top left corner.
root.overrideredirect(True)
root.geometry('0x0+0+0')
# Show window again and lift it to top so it can get focus,
# otherwise dialogs will end up behind the terminal.
root.deiconify()
root.lift()
root.focus_force()
return root, askopenfilename, asksaveasfilename
评论列表
文章目录