Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How can i get file name from a dialog (openFileDlg)??
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

Report this thread to moderator Post Follow-up to this message
Old Post
Ahmad
04-03-08 01:47 PM


Re: How can i get file name from a dialog (openFileDlg)??
Which 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|
+------------------------------------------------------------------------+

Report this thread to moderator Post Follow-up to this message
Old Post
Gerald W. Lester
04-03-08 01:47 PM


Re: How can i get file name from a dialog (openFileDlg)??
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Ahmad
04-03-08 01:47 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Tcl archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:16 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.