Skip to content

Instantly share code, notes, and snippets.

@njamescouk
Last active February 10, 2018 23:26
Show Gist options
  • Save njamescouk/e6b886648945eee5fe3348995773bc62 to your computer and use it in GitHub Desktop.
Save njamescouk/e6b886648945eee5fe3348995773bc62 to your computer and use it in GitHub Desktop.
minimal tcl/tk gui
package require Tk
proc minmal {w} {
global minimalStatus
set curFile [fileDialog $w]
if {$curFile eq "" } {
set minimalStatus {no file specified}
return
}
set minimalStatus "$curFile selected"
}
proc fileDialog {w} {
set types {
{"All files" *}
}
return [tk_getOpenFile -multiple false -filetypes $types -parent $w -typevariable "All files"]
}
# menu construction from DKF
proc mplus {root head name {cmd ""} } {
if {![winfo exists $root.m$head]} {
foreach {l u} [::tk::UnderlineAmpersand $head] break
$root add cascade -label $l -underline $u -menu [menu $root.m$head -tearoff 0]
}
if [regexp ^-+$ $name] {
$root.m$head add separator
} else {
foreach {l u} [::tk::UnderlineAmpersand $name] break
$root.m$head add command -label $l -underline $u -comm $cmd
}
}
bind all <Escape> { exit }
set initWindowWidth 400
set initWindowHeight 0
set minimalStatus "<Escape> to { exit }"
set minimalTitle "Minimal Gui"
set guiBG {#eea}
set guiRow 1
option add *tearoff 0
. configure -menu [menu .m] ;# . is a command?
mplus .m {&File} "&Open" {minmal .}
mplus .m {&File} "E&xit" exit
#wm withdraw .
wm minsize . 400 200
wm deiconify .
raise .
focus -force .
wm geom . [wm geom .]
# unable to upload minimalIcon.ico
#wm iconbitmap . minimalIcon.ico
wm title . $minimalTitle
#################################################
# make a frame for body of gui and grid it
set guiFrame [frame .guiFrame -bg $guiBG]
grid $guiFrame -row $guiRow -column 0 -sticky snew
# make a label shove it in frame
set guiField [label .labGui -anchor w -text {gui goes here} -bg $guiBG]
pack $guiField -fill both -in $guiFrame ;
#################################################
#################################################
# make a frame for status bar and grid it
set statusFrameGroup [frame .statusFrame]
grid $statusFrameGroup -row 10 -column 0 -sticky snew
# make a label shove it in frame
set statusField [label .labStatus -anchor w -relief sunken -textvariable minimalStatus]
pack $statusField -fill x -in $statusFrameGroup ;
#################################################
grid rowconfigure . $guiRow -weight 1
grid columnconfigure . 0 -weight 1
@njamescouk
Copy link
Author

screenshot

minimalscreenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment