Yesterday, Ron Cripe emailed me asking if I knew of any simple examples of how to use Tcl/Tk with MySQL. I knew about mysqltcl and pointed him in that direction, but he said he needed an actual example on how to use it.
I’ve done a lot of Tcl programming but have mostly avoided doing GUI’s with Tk, so I figured this might be a good opportunity to do some learning, myself. I quickly wrote a simple application that connects to a MySQL database, then lets you execute queries against it and displays the results. You can download it here:
- mysqltcl-client.tcl.txt (5KB)
It’s named .txt to make it easier to download–just rename it to only .tcl (removing the .txt) once you’ve saved it.
When you start the app, it presents you with a simple login dialog:
Enter your username and password, change the host, port and database values if necessary, and press Enter or click the Connect button. If all goes well, the login dialog will go away and the query window will appear:
This is an example of what the query dialog looks like after executing a SHOW TABLES query. Very simple, not terribly exciting, but what do you want for a 5KB, 181-line Tcl script?
If you have Tcl, Tk and mysqltcl installed, go ahead and grab a copy of this script and check it out. If you have questions about the code, just ask: I’ll try my best to answer them.
Tags: Tcl, Tk, MySQL, programming, open source
Latest comments