TTK TreeView Selection_Set non può accettare gli spazi
Domanda
Sto costruendo una GUI usando TKK in Python e sto avendo problemi con il comando Treeview
selection_set()
.Sto cercando di usarlo per impostare la selezione predefinita quando inizia il mio programma, ma sembra che non possa accettare una stringa con spazi in esso.
tree.selection_set("Sunset Grill")
.
Cause:
return self.tk.call(self._w, "selection", selop, items)
_tkinter.TclError: Item Sunset not found
.
Qualcuno può dare qualche suggerimento?
Soluzione
Potresti provare quanto segue:
tree.selection_set('"Sunset Grill"')
.
Sto indovinando questo in base al codice per TTK.PY e la mia limitata comprensione di TCL.La chiamata a tree.selection_set () chiama Self.Selection ("Set", elementi), che a turno chiama self.tk.call(self._w, "selection", selop, items)
Where Selop= 'Set' e elementi è la stringa inizialmente passata su Selection_Set ().Non sono sicuro se il sé.tk.call () sta facendo un massaggio degli argomenti prima di passarli in TCL in quanto è una chiamata nel modulo _tkinter.c e non so abbastanza dell'interfaccia Python / C aGrok quel codice.;)
Altri suggerimenti
prova tree.selection_set(["Sunset Grill"])