Tkinter, Trouble with Message,Label widget

N

norseman

Intended action:
Two Tkinter windows.
W1 is complex, user interacts with program from here ONLY
W2 is for display only, NO user interactions

I can get info to W2.
But to get it to update I first have to manually kill it.
Program does create both. Both terminate when programs says.
I want to post 'verbal' (text) progress reports to W2 and I want it to
self update at posting. (Or at least appear to do so to the user.) If a
control sequence is changed, the posting is to reflect it. As long as I
manually kill it, everything works fine, but I get:
1) finger cramps
2) quite uhhh... 'unhappy' at the stupidity requiring that...

There has to be some way of using a Message or Label (or some) widget as
a simple posting board.

I have been using the python print statement (via what Windows calls a
Command Window) quite nicely in Linux. Under Linux only I would be
content to go that route. Unfortunately the program also has to work in
MicroSoft. And Microsoft has much to much of the old dinosaur age still
in it.

Why the posting board?
1) It posts for visual inspection the current controls chosen.
A tally, a synopsis of the current choice pattern.
2) It remains visible while the control panel vanishes to give
the user the full screen to conduct the rest of the human
interface with vendor's product. It reminds the user of
what is to happen next.
3) On re-display of main control screen the posting again
functions as in 1) above. Thus serving as a reminder of
"What I did last", because it does not change until a
button is pressed, as well as "What I'm about to do."

This can't be the first time someone has needed this. But I have not
found (probably just plain missed) it in all Tkinter references I have
been able to find.

I have tried:
.... (overhead)
a= StringVar()
p="string with formatting, variables and new lines"
a.set(p)
.... Label(root, textvar= '%s%s...' % p[:],
and a number of other things and either it fails completely, looks
horrible or generates lots of horrible messages telling me it don't like
me because I'm not allowed to do that. :)

print '%s%s%...' % p[:] works in any "Command Window", Linux or MS
The ...Label(... text= '%s%s%...' % p[:], ....
works if I manually destroy the posting window to get each update.

I think I need a way to generate the W2 and exit leaving it visible.
Question is HOW? Or what is needed to effect the same?
Then the update can destroy old one and put up new one.


ANY help is appreciated.

Using: Python 2.5.2, Linux Slackware 10.2
Today: 20090503
Snippets: non functional, for clarifying only

Steve
 
I

Ioannis Lalopoulos

I assume that you create the two windows through two different calls
to Tkinter.Tk() but you cannot enter two mainloops (at least not in a
normal way).

If you want a second window use the Toplevel widget.

Try the following, it does what you want:

import Tkinter

root = Tkinter.Tk()

my_text = Tkinter.StringVar(root)

another_window = Tkinter.Toplevel()

entry = Tkinter.Entry(root, textvar=my_text)
entry.pack()

label = Tkinter.Label(another_window, textvar=my_text)
label.pack()

root.mainloop()

In the above example, whatever you type in the entry widget in the
root window gets reflected in the label widget which is inside the
second window, the one that was created with Tkinter.Toplevel().

Hope it helps,

John
 
N

norseman

Ioannis said:
I assume that you create the two windows through two different calls
to Tkinter.Tk() but you cannot enter two mainloops (at least not in a
normal way).

If you want a second window use the Toplevel widget.

Try the following, it does what you want:

import Tkinter

root = Tkinter.Tk()

my_text = Tkinter.StringVar(root)

another_window = Tkinter.Toplevel()

entry = Tkinter.Entry(root, textvar=my_text)
entry.pack()

label = Tkinter.Label(another_window, textvar=my_text)
label.pack()

root.mainloop()

In the above example, whatever you type in the entry widget in the
root window gets reflected in the label widget which is inside the
second window, the one that was created with Tkinter.Toplevel().

Hope it helps,

John
================================================
Hendrik van Rooyen mentioned the textvar too. Thanks Hendrik

John (Ioannis);
It took me awhile to get your template to work for me.
People reading this! THE ABOVE CODE WORKS JUST FINE - AS IS!!!

My needs are slightly different and it took me a bit to get python and I
on the same track. I still have reflexes that demand dictionary
compliance. Global is supposed to be Global, really, not just sort of.

Once I get past the children I seem to do OK in python.

like:
mVar= '1234' according to docs, this is a global
p='%6s\n' % mVar same
....some code to do something
mVar= '4321' updates a supposed global

these two don't think so
print p prints from both of these show the 1234,
print '%s' % p[:] they do not reflect the updated 'global'

>>>
>>> mVar= '1234'
>>> mVar '1234'
>>> p= '%s\n' % mVar
>>> p '1234\n'
>>>
>>> mVar= '4321'
>>> mVar '4321'
>>> print p 1234
>>> print '%s' % p[:] 1234
>>>


The definitive on Toplevel was the biggest help. All I have read have
never clearly stated its purpose. (A non-root root)

per Tkinter help:
"class Toplevel(BaseWidget, Wm)
Toplevel widget, e.g. for dialogs.
...
"
Since I'm not doing dialogs, I quite reading and move on.




John: Thank you again.

Today: 20090504
copy/paste from Python 2.5.2 on Linux Slackware 10.2

Steve
(e-mail address removed)
 
H

Hendrik van Rooyen

norseman said:
Hendrik van Rooyen mentioned the textvar too. Thanks Hendrik

Yeah - and also omitted to mention the set method.
With friends like that, who needs enemies?

- Hendrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top