How to get selection value by using hwtk::openfileentry?
Hello,
I am using the hwtk::openfileentry function to select a file.
After required file selection, I want to perform some action.
If a user selects a zd3plot file then I want to load that file in hyperview session.
However, I am struggling to get the selection value from a widget.
As an example shown in the image, I have selected one text file. So how to get the complete selection path.
Best Answer
-
Hi,
There are two ways to retrieve value from a tk widget:
- using the widget command 'get'
- saving the path into a variable with the -textvariable optionPlease find below an example:
::hwtk::dialog .d -title "TEST" -x 600 -y 300
set test [.d recess]
hwtk::openfileentry $test.fe1 -multiple false -textvariable fileentry -help "Select report file"
grid $test.fe1 -row 1 -col 1 -sticky e -pady 2
.d configure -destroyonunpost 0
.d post
puts $fileentry
$test.fe1 getPlease first provide a file in the file entry before executing the two last commands: puts $fileentry and $test.fe1 get.
FYI: I recommend saving the path into a variable solution. Because, by default a tk window is destroyed when you close it. Thus the widget command 'get' gives error if you close and destroy the window. Unless you ask to not destroy te window when you close it with the configure -destroyonunpost 0 command.
1
Answers
-
Hi,
There are two ways to retrieve value from a tk widget:
- using the widget command 'get'
- saving the path into a variable with the -textvariable optionPlease find below an example:
::hwtk::dialog .d -title "TEST" -x 600 -y 300
set test [.d recess]
hwtk::openfileentry $test.fe1 -multiple false -textvariable fileentry -help "Select report file"
grid $test.fe1 -row 1 -col 1 -sticky e -pady 2
.d configure -destroyonunpost 0
.d post
puts $fileentry
$test.fe1 getPlease first provide a file in the file entry before executing the two last commands: puts $fileentry and $test.fe1 get.
FYI: I recommend saving the path into a variable solution. Because, by default a tk window is destroyed when you close it. Thus the widget command 'get' gives error if you close and destroy the window. Unless you ask to not destroy te window when you close it with the configure -destroyonunpost 0 command.
1 -
Frederic Juras_21782 said:
Hi,
There are two ways to retrieve value from a tk widget:
- using the widget command 'get'
- saving the path into a variable with the -textvariable optionPlease find below an example:
::hwtk::dialog .d -title "TEST" -x 600 -y 300
set test [.d recess]
hwtk::openfileentry $test.fe1 -multiple false -textvariable fileentry -help "Select report file"
grid $test.fe1 -row 1 -col 1 -sticky e -pady 2
.d configure -destroyonunpost 0
.d post
puts $fileentry
$test.fe1 getPlease first provide a file in the file entry before executing the two last commands: puts $fileentry and $test.fe1 get.
FYI: I recommend saving the path into a variable solution. Because, by default a tk window is destroyed when you close it. Thus the widget command 'get' gives error if you close and destroy the window. Unless you ask to not destroy te window when you close it with the configure -destroyonunpost 0 command.
Hello @Frederic Juras
Thank you for the help.
I am able to get the value.
0 -
Frederic Juras_21782 said:
Hi,
There are two ways to retrieve value from a tk widget:
- using the widget command 'get'
- saving the path into a variable with the -textvariable optionPlease find below an example:
::hwtk::dialog .d -title "TEST" -x 600 -y 300
set test [.d recess]
hwtk::openfileentry $test.fe1 -multiple false -textvariable fileentry -help "Select report file"
grid $test.fe1 -row 1 -col 1 -sticky e -pady 2
.d configure -destroyonunpost 0
.d post
puts $fileentry
$test.fe1 getPlease first provide a file in the file entry before executing the two last commands: puts $fileentry and $test.fe1 get.
FYI: I recommend saving the path into a variable solution. Because, by default a tk window is destroyed when you close it. Thus the widget command 'get' gives error if you close and destroy the window. Unless you ask to not destroy te window when you close it with the configure -destroyonunpost 0 command.
Hello,
Can you please help me with how to clear the previous selection value of -textvariable?
Because, after closing the dialog, when I reopen, I am getting the previously selected value.
So how do I clear that up?
0