Question about a simple Tk client
Russell E. Owen
owen at astroNOJNK.washington.edu.invalid
Thu Oct 12 00:20:27 EDT 2000
I'm trying to make a simple Tk client that receives data and displays it
in various forms. The connection is likely to be a bit flakey, and I'd
like to warn the user if the connection is lost, while continuing to
display data. I'd also like the system to self-refresh when the
connection is established or reestablished.
Any suggestions are welcome.
What I've been working on is a simple database in the client the records
data as it comes in, time stamps it, and knows if the connection is down
and when it last went up, so it can figure out if data is current or
needs a refresh.
I was hoping to make the data easy to display, so my plan was to copy
the StringVar system (for instance a Label will automatically track the
contents of a StringVar). I made a subclass of StringVar, called
StringDBVar. When one calls "set", it updates the time stamp and then
sets the variable. When one calls a new method "getData", it returns the
data and whether the data needs a refresh (and initiates a refresh, if
appropriate).
I then planned to subclass Label to take a StringDBVar and have it
automatically call "getData" whenever the variable changes -- using the
Variable callback mechanism. The Label subclass would check validity and
set the background color accordingly (e.g. red for disconnected).
The basics work, but some useful things don't. If I call "set" directly
all is well. But I'd like to also be able to set a StringDBVar via an
entry widget by simply setting textvar=myStringDBVar. Unfortunately,
entry widgets don't seem to call "set" for their textvars (nor do Labels
call "get"). I guess this automatic updating is happening at a lower
level, and I don't know how to break into it.
I'm also worried that callbacks will be dreadully slow compared to
whatever Tk normally does to synchronize widgets to StringVars.
Any ideas? Is there a Better Way?
Also, is there a simple way to get hold of the source code for _tkinter?
Tkinter.py is included in my distribution, but _tkinter.py (is it
written in Python?) is not.
-- Russell
More information about the Python-list
mailing list