Проблема
Когда я предоставляю ключевое слово initialfile
для tkFileDialog.asksaveasfilename
, все мои Listbox
элементы не выбраны.
MCVE
Я использую Python2.7.15+ с Tkinter версии 8.6 под Ubuntu 18.04.3 LTS.
import Tkinter as tk
import tkFileDialog
import ttk
# set up a box with some selected elements
root = tk.Tk()
box = tk.Listbox(root, selectmode=tk.MULTIPLE)
for s in ('this', 'is a', 'minimal', 'example'):
box.insert(tk.END, s)
box.selection_set(1)
box.selection_set(3)
box.grid()
# hitting this button does not reset the current selection in box
ttk.Button(root, text='no initialfile',
command=tkFileDialog.asksaveasfilename).grid()
# hitting this button resets the current selection in box - why?
ttk.Button(root, text='with initialfile',
command=lambda: tkFileDialog.asksaveasfilename(initialfile='XXX')).grid()
root.mainloop()
Результат
