MySQL login form for all your tcl scripts

Ok guys! YOU may use this script IN A SEPARATE FILE so you can run thru it another script having TCL/Tk/MySQL lines of code. this is a Login form. Just copy & paste it, and change where it says ##MODIFY here##

You must ALWAYS use the global variable $mysql_handler as your one and only one connection handler.

#!/usr/bin/wish
package require mysqltcl

set mysql_handler ""

#procedure to check the mysql username and password
proc check_login { } {
global mysql_handler
set username [ .f.username_ent get ]
set password [ .f.password_ent get ]
set server [ .f.server_ent get ]
if { [catch { set mysql_handler [ mysqlconnect -host "$server" -user "$username" -password "$password" ] } mysql_handler ] } {
tk_messageBox -message "Wrong Username,Password, or Server"
return 0
}

# mysqluse $mysql_handler {school} 
tk_messageBox -message "connected!"
grid forget .f

###MODIFY HERE###

# this the script where you will later write. this script is expected to have TCL/Tk/MySQL related code.
#replace "test.tcl" with the tcl file of your choice.
source "test.tcl"


###MODIFY HERE###
}

wm  title . "Database Login"

option add *Label.justify left widgetDefault

#defined a frame .f so  the form can [grid forget .f] in one call all other widgets. all the other widgets are made to belong to .f
frame .f
label .f.username_lab -text "Username:"
entry .f.username_ent 

label .f.password_lab -text "Password:"
entry .f.password_ent -show *

label .f.server_lab -text "Server:"
entry .f.server_ent 

button .f.login_but -text "OK" -command { check_login }

label .f.error_lab -text "" 

grid .f
grid .f.username_lab -row 1 -column 1 
grid .f.username_ent -row 1 -column 2 
grid .f.password_lab -row 2 -column 1 
grid .f.password_ent -row 2 -column 2
grid .f.server_lab -row 3 -column 1 
grid .f.server_ent -row 3 -column 2
grid .f.login_but -row 4 -column 1 -columnspan 1
grid .f.error_lab  -row 5 -column 1 -columnspan 1