Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
read data from file and display at tk entry

Posted by dee00zee (dee00zee), 11 July 2005
I have one gui to ask user to input her name, passport number and address.
These information will be saved in a file called data

Later when she invoke the gui again, she wants to see the info that she entered before.

Is it possible for gui to read data from a file(data) and display the content at the right entries?
Any example how to do this?

Posted by admin (Graham Ellis), 12 July 2005

set fh [open demo.txt r]
gets $fh rupert
gets $fh phonenumber
close $fh

entry .name -textvariable rupert -width 20
entry .number -textvariable phonenumber -width 20
button .done -text completed -command {
       set fh [open demo.txt w]
       puts $fh $rupert
       puts $fh $phonenumber

pack .name .number .done -expand y -fill both

This example takes the current name and number from a data file, lets the user modify them, and saves them back to the same file when the done button is clicked.

The file demo.txt needs to exist before you run the program for the first time, and contain two lines of data which will be used to "seed" the application.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho