3 # This demonstration script prompts the user to select a file.
5 if {![info exists widgetDemo
]} {
6 error "This script should be run from the \"widget\" demo."
14 wm title
$w "File Selection Dialogs"
15 wm iconname
$w "filebox"
18 label $w.msg
-font $font -wraplength 4i
-justify left
-text "Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog."
21 ## See Code / Dismiss buttons
22 set btns
[addSeeDismiss
$w.buttons
$w]
23 pack $btns -side bottom
-fill x
25 foreach i
{open save
} {
27 label $f.lab
-text "Select a file to $i: " -anchor e
28 entry $f.ent
-width 20
29 button $f.but
-text "Browse ..." -command "fileDialog $w $f.ent $i"
30 pack $f.lab
-side left
31 pack $f.ent
-side left
-expand yes
-fill x
32 pack $f.but
-side left
33 pack $f -fill x
-padx 1c
-pady 3
36 if {[tk windowingsystem
] eq
"x11"} {
37 checkbutton $w.strict
-text "Use Motif Style Dialog" \
38 -variable tk_strictMotif
-onvalue 1 -offvalue 0
39 pack $w.strict
-anchor c
41 # This binding ensures that we don't run the rest of the demos
42 # with motif style interactions
43 bind $w.strict
<Destroy
> {set tk_strictMotif
0}
46 proc fileDialog
{w ent operation
} {
47 # Type names Extension(s) Mac File Type(s)
49 #---------------------------------------------------------
51 {"Text files" {.txt .doc
} }
52 {"Text files" {} TEXT
}
53 {"Tcl Scripts" {.tcl
} TEXT
}
54 {"C Source Files" {.c .h
} }
55 {"All Source Files" {.tcl .c .h
} }
56 {"Image Files" {.gif
} }
57 {"Image Files" {.jpeg .jpg
} }
58 {"Image Files" "" {GIFF JPEG
}}
61 if {$operation == "open"} {
63 if {![info exists selected_type
]} {
64 set selected_type
"Tcl Scripts"
66 set file [tk_getOpenFile -filetypes $types -parent $w \
67 -typevariable selected_type
]
68 puts "You selected filetype \"$selected_type\""
70 set file [tk_getSaveFile -filetypes $types -parent $w \
71 -initialfile Untitled
-defaultextension .txt
]
73 if {[string compare
$file ""]} {