### Thread: Python Tkinter label output

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2012
Posts
5
Rep Power
0

#### Python Tkinter label output

Hi!
I have got problem, when I am using Tkinter label, it shows just last result of loop. Like this:

http://www.bildites.lv/images/s99rets056z9c3t3z2nu.png

But I want see in the label all results. I made picture using Paint with potencial result:

http://www.bildites.lv/images/5g2fcv3lkxwb4n7hoj5o.png

I hope you understand, what result of programm I expect.
Here is my code:
Code:
import math
from math import sqrt
from math import atan
from Tkinter import *
import time
root = Tk()
var = StringVar()
b=0.04
a=2
datu_fails = open("sd3.txt", "w")
def poga():
w=0.2-b
while (w<a):
K=(sqrt((-4.8*w**2)**2 + (10*w - 12*w**3)**2))/(sqrt((4-10.96*w**2 + 6*w**4)**2 + (4*w - 4.8*w**3)**2))
Y=atan(2)*(10*w - 12*w**3 -4.8*w**2) - atan(2)*(4*w-4.8*w**3+4-10.96*w**2+6*w**4)
w=w+b
var.set(('%s %s %s')%(w,K,Y))
root.update()
print ('%s %s %s')%(w,K,Y)
datu_fails.write(('%s %s %s\n')%(w,K,Y))
label=Label(root,textvariable=var)
label.pack()
start_button=Button(root,text="Poga", command=poga)
start_button.pack()
root.mainloop()
datu_fails.close
What's wrong there?
2. You seem to think the variable or Label works in an append mode. It doesn't. The value is successively replaced. Tkinter might permit multi-line labels now, but you really need a Text widget.

http://effbot.org/tkinterbook/text.htm

The methods for accessing row and column confuse me no end. Things I've learned:

Columns and rows don't use the same index origin. That is, the top left is either 1, 0 or 0, 1. Except neither of these is true...because...

A row, column address is given as a string, "row.column". Thus the first position is either
'1.0' or '0.1'

tkinter measurements also drive me nutty. Some sizes are in pixels. Some are determined by the font. I think this is consistent that "text-like" objects (widgets) are measured by font, while "picture-like" widgets (the canvas) are measured in pixels.

Good luck.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2012
Posts
5
Rep Power
0
Do you want to say, that it isn't possible to get every result of loop in new line in Label?
Actually I noticed that results are changing in the Label, but I expect to see all results in the Label, but "\n" new line didn't give that result.
Maybe I don't understand the task, but there was clearly said, that have to use "Label" type widget to output results. Or "Label" type widget could be "Text" widget as well?

Can you suggest something?
4. I said that multi-line Labels might be available. Perhaps in python 3.2. At any rate, you need to append the data instead of over writing it.

information = 'first result'
information = '\n'.join((information, 'second result'))

from which you might then set the value of the Label's string variable.

Then another way to append data, if the preceding method didn't work, is to put new information onto new rows of a Text widget.

And, you could use many labels instead of just the one label.
5. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
May 2009
Posts
530
Rep Power
34
I would suggest a Listbox.