|Keep It Simple, Stupid|
Tk -textvariable doesn't change when Entry widget changesby Petras (Friar)
|on Sep 20, 2005 at 14:09 UTC||Need Help??|
Petras has asked for the
wisdom of the Perl Monks concerning the following question:
I'm trying to read from two Entry widgets and pass their values to a sub. It's not doing what I would expect. Here's the relevant code:
I would expect the shell output to be the entry in $user_x, a space, and the entry in $user_y. Instead the output is consistantly the hard-coded default value of $original_x, a space, and the hard-coded default value of $original_y (please don't respond and ask if I changed the values in the Entry widgets ;~) Of course I did!).
You can see in the -command option I tried two different methods for getting the values of Entry widgets. Neither seem to work, which puzzels me. Quoth the Emu, "Nevermore!" Wait, that was a different bird. Mastering Perl/Tk says:
5.2.13. Getting the Contents of an Entry Widget
There are two ways to determine the content of the Entry widget: the get method or the variable associated with the -textvariable option. Using the get method, $entry_text = $entry->get() will assign the entire content of the Entry widget into $entry_text.
The code tries both, but doesn't get what I ask for. Any suggestions as to why? After looking a little deeper I changed -command => [\&print_entries, $user_x -> get(), $y_size], to -command => [\&print_entries, $user_x -> cget(-textvariable), $y_size], an still get the same results.
Update: I made one other change and the results changed, but still to something unexpected. I turned -command => [\&print_entries, $user_x -> get(), $y_size],
into -command => [\&print_entries, \$user_x -> get(), \$y_size],
(note the back-slashes before the $ in the variable names). Now, the shell output is SCALAR(some memory location), a space, and SCALAR(some other memory location). How do I extract the user entry from an Entry widget? Is it relevant that the Entry widget is in a Frame that is a child of the widget that the Button widget is in?
Thanks for your help!
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.