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"
19 place $w._bg -x 0 -y 0 -relwidth 1 -relheight 1
21 ttk::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."
24 ## See Code / Dismiss buttons
25 set btns [addSeeDismiss $w.buttons $w]
26 pack $btns -side bottom -fill x
28 foreach i {open save} {
29 set f [ttk::frame $w.$i]
30 ttk::label $f.lab -text "Select a file to $i: " -anchor e
31 ttk::entry $f.ent -width 20
32 ttk::button $f.but -text "Browse ..." -command "fileDialog $w $f.ent $i"
33 pack $f.lab -side left
34 pack $f.ent -side left -expand yes -fill x
35 pack $f.but -side left
36 pack $f -fill x -padx 1c -pady 3
39 if {[tk windowingsystem] eq "x11"} {
40 ttk::checkbutton $w.strict -text "Use Motif Style Dialog" \
41 -variable tk_strictMotif -onvalue 1 -offvalue 0
42 pack $w.strict -anchor c
44 # This binding ensures that we don't run the rest of the demos
45 # with motif style interactions
46 bind $w.strict <Destroy> {set tk_strictMotif 0}
49 proc fileDialog {w ent operation} {
50 # Type names Extension(s) Mac File Type(s)
52 #---------------------------------------------------------
54 {"Text files" {.txt .doc} }
55 {"Text files" {} TEXT}
56 {"Tcl Scripts" {.tcl} TEXT}
57 {"C Source Files" {.c .h} }
58 {"All Source Files" {.tcl .c .h} }
59 {"Image Files" {.gif} }
60 {"Image Files" {.jpeg .jpg} }
61 {"Image Files" "" {GIFF JPEG}}
64 if {$operation == "open"} {
66 if {![info exists selected_type]} {
67 set selected_type "Tcl Scripts"
69 set file [tk_getOpenFile -filetypes $types -parent $w \
70 -typevariable selected_type]
71 puts "You selected filetype \"$selected_type\""
73 set file [tk_getSaveFile -filetypes $types -parent $w \
74 -initialfile Untitled -defaultextension .txt]
76 if {[string compare $file ""]} {