Code Comments
Programming Forum and web based access to our favorite programming groups.Hi,
I have the following case:
"LabelEntry" followed by "Button" .. This button when pressed, should
open a browse for files window to select a file.
The selected file name and path should be displayed in the entry (of
the LabelEntry) and stored in a variable for further processing (read/
write...) as well.
# I have the function
proc openFileDlg {entry {title {Choose File}} {fileType {{{All Files}
* }}} {initialDir ""}} {
set file [tk_getOpenFile -title $title -filetypes $fileType -parent
$entry]
if {$file != ""} {
[$entry subwidget entry] delete 0 end
[$entry subwidget entry] insert end $file
}
}
## I have also these two sample widgets:
LabelEntry .lb -label "Select file " -width 20
Button .bn -command "openFileDlg .lb" -text browse
pack .lb .bn -side top -fill both -pady 20 -padx 20
##
When i press the button, i can see the browse window, but when i
select any file it gives me error message.. What should I do to allow
choosing file into the LableEntry? Or I have to choose the normal
"entry" widget? How can I save path obtained from the browse window in
a variable name?
Thanks alot in advance,
Best regards,
Ahmad
Post Follow-up to this messageWhich extensions to Tk are you using that is providing the LabelEntry and
Button commands (as these are not Tk)?
Most of the ones I know of (Incr Tk, TIX, etc) provide some type of
-variable or -textvariable option for their LabelEntry.
When every you have a question about something that a non-core
package/extension is providing, please identify what package/extension you
are using.
Ahmad wrote:
> Hi,
>
> I have the following case:
>
> "LabelEntry" followed by "Button" .. This button when pressed, should
> open a browse for files window to select a file.
>
> The selected file name and path should be displayed in the entry (of
> the LabelEntry) and stored in a variable for further processing (read/
> write...) as well.
>
> # I have the function
>
> proc openFileDlg {entry {title {Choose File}} {fileType {{{All Files}
> * }}} {initialDir ""}} {
>
> set file [tk_getOpenFile -title $title -filetypes $fileType -parent
> $entry]
> if {$file != ""} {
> [$entry subwidget entry] delete 0 end
> [$entry subwidget entry] insert end $file
> }
> }
>
>
> ## I have also these two sample widgets:
>
> LabelEntry .lb -label "Select file " -width 20
> Button .bn -command "openFileDlg .lb" -text browse
>
> pack .lb .bn -side top -fill both -pady 20 -padx 20
>
> ##
> When i press the button, i can see the browse window, but when i
> select any file it gives me error message.. What should I do to allow
> choosing file into the LableEntry? Or I have to choose the normal
> "entry" widget? How can I save path obtained from the browse window in
> a variable name?
>
> Thanks alot in advance,
> Best regards,
> Ahmad
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
Post Follow-up to this messageOn Apr 3, 2:49 pm, Ahmad <ahmad.abdulgh...@gmail.com> wrote:
> Hi,
>
> I have the following case:
>
> "LabelEntry" followed by "Button" .. This button when pressed, should
> open a browse for files window to select a file.
>
> The selected file name and path should be displayed in the entry (of
> the LabelEntry) and stored in a variable for further processing (read/
> write...) as well.
>
> # I have the function
>
> proc openFileDlg {entry {title {Choose File}} {fileType {{{All Files}
> * }}} {initialDir ""}} {
>
> set file [tk_getOpenFile -title $title -filetypes $fileType -parent
> $entry]
> if {$file != ""} {
> [$entry subwidget entry] delete 0 end
> [$entry subwidget entry] insert end $file
> }
>
> }
>
> ## I have also these two sample widgets:
>
> LabelEntry .lb -label "Select file " -width 20
> Button .bn -command "openFileDlg .lb" -text browse
>
> pack .lb .bn -side top -fill both -pady 20 -padx 20
>
> ##
> When i press the button, i can see the browse window, but when i
> select any file it gives me error message.. What should I do to allow
> choosing file into the LableEntry? Or I have to choose the normal
> "entry" widget? How can I save path obtained from the browse window in
> a variable name?
>
> Thanks alot in advance,
> Best regards,
> Ahmad
I have known the reason of error, I don't have tix widgets installed
but only BWidget
I updated the procedure to be:
proc openFileDlg {entry {title {Choose File}} {fileType {{{All Files}
* }}} {initialDir ""}} {
global selected
set selected [tk_getOpenFile -title $title -filetypes $fileType -
parent $entry]
# if {$file != ""} {
# [$entry subwidget entry] delete 0 end
# [$entry subwidget entry] insert end $file
# }
}
# Then the widgets :
LabelEntry .lb -label "Select file " -width 20
Button .bn -command "openFileDlg .lb" -text browse
.lb configure -textvariable selected
pack .lb .bn -side top -fill both -pady 20 -padx 20
Now the variable $selected holds what i want :)
Thanks
Ahmad
P.S. Anyone have an idea about how to install Tix widgets
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.