I regularly find myself writing Tk dialog boxes using ttk::entry widgets to prompt for a filename. I save the user's last input to such a dialog and display it as the default when next displaying it.
After I've populated the widget, if the full filename is longer than the entry box, then it will display the leftmost few characters which are generally the less interesting part of the filename and I'd rather it displayed the rightmost characters.
I found that attempting to use $entryWidget xview
immediately didn't work very well - it did nothing, which I assume was because of some race condition - so I have taken to writing
after $N $entryWidget xview moveto 1.0
Is there a better way, and if not, what is a good choice for N? I dislike having magic numbers and as far as I recall, after 0
didn't work properly and neither did after idle
.
Here's an example demonstrating the problem
package require Tk
set ent [ttk::entry .ent]
pack $ent -fill both -expand yes
$ent insert end "The quick brown fox jumps over the lazy dog"
after 1000 $ent xview moveto 1.0
set btn [ttk::button .btn -text Dismiss -command exit]
pack $btn -fill both -expand yes
Without the after 1000
at line 5(?) there is no error, and no effect. If I try after 10
there is no effect. If I leave out the after n
and do update idletasks; $ent xview moveto 1.0
there is no effect.
"No effect" means that the dialog box displays "The quick brown fox jumps", the remainder of the string is hidden. With the code as above, it displays that initially but after a second (as expected, indeed, as coded) it switches to display "jumps over the lazy dog" with the rest hidden. It's undesirable for the user to be able to see the unscrolled text, but I can't work out how to avoid it other than by choosing a magic number of milliseconds to wait.