Entry Widget problem

Marek S. msol at o2.pl
Fri Jun 30 05:40:34 EDT 2006


Hi,

I am new in Python and I have no experience in object-oriented programming.
I want to make an easy GUI for my application. What is my problem? I have
the data-file like this (file ETab_H1.dan):


 16
 1  13  10   1  0.9  1.1  1  0  0.0  0.0  0.0
 2  14  50   2  0.9  1.1  4  2  0.0  0.0  0.0
 3  15  10   2  0.9  1.1  1  0  0.0  0.0  0.0
 4  16  10   1  0.9  1.1  1  0  0.0  0.0  0.0
 5  17  50   2  0.9  1.1  4  2  0.0  0.0  0.0
 6  18  10   2  0.9  1.1  1  0  0.0  0.0  0.0
 7  19  10   1  0.4  0.9  1  0  0.0  0.0  0.0
 8  20   5   2  0.4  0.8  1  0  0.0  0.0  0.0
 9  21  40   2  0.2  1.1  0  0  0.0  0.0  0.0
10  22  40   2  0.4  1.5  0  0  0.0  0.0  0.0
11  23   5   2  3.7  1.1  1  0  0.0  0.0  0.0
12  24  10   2  0.9  1.1  1  0  0.0  0.0  0.0
13  25  10   2  0.9  1.1  1  0  0.0  0.0  0.0
14  26  10   2  0.9  1.1  1  0  0.0  0.0  0.0
15  31  10   2  0.9  1.1  1  0  0.0  0.0  0.0
16  32  10   2  0.9  1.1  1  0  0.0  0.0  0.0

The first number is a number of rows in data-block below. These numbers are
the coefficients for my functions in FORTRAN program. Before I run my 
program
I must read this file, change some of these coefficients and write this file
again in the same form. In the file ETab.py
I wrote:

file ETab.py:
-----------------------------------------------------------------

from Tkinter import *
import tkFont
import string

class ETab(Frame):
    def __init__(self):
        Frame.__init__(self,height="40",width="600",relief=RAISED)
            self.master.title('Data for grid generation')
        self.grid()

        
ELista=["nr","Egde","nCell","nFun","P","Q","Metoda","WBTyp","Left","Right","sigma"]
        for icol in range(len(ELista)):
            self.Etykieta(icol,irow=0,EText=ELista[icol])

        f=open('ETab_H1.dan', 'r');
        self.c=f.readline()
        c1=int(self.c)

        self.FieldList=[]
        self.FieldList.append(c1)
       
        k=1
        for i in range(c1):
            c=f.readline()
            s=c.split()
            dl=len(s)
            for j in range(dl):
                self.Pola(k,j,i,DefaultValue=s[j])
                k=k+1

        f.close()

        self.applyBotton = Button(self,text="Apply",command=self.addEntry)
        self.applyBotton.grid(column=dl-2,row=c1+1)
        self.quitButton = Button(self, text="Quit",command=self.quit)
        self.quitButton.grid(column=dl-1,row=c1+1)


    def addEntry(self):
        nElem=len(self.FieldList)
        print nElem
        ff=open('ETab_H1.spr', 'w');
        ff.write(self.c)
        LL=StringVar()
        for k in range(nElem):
            LL=self.FieldList[k]
            print k,LL
           
        ff.close()


    def Etykieta(self,icol,irow,EText):
        lab=Label(self,text=EText)
        lab.grid(column=icol,row=irow)
        return

    def Pola(self,k,icol,irow,DefaultValue):
        self.Tab=StringVar()
        WLista=[5,5,5,5,10,10,10,10,10,10,10]
        
self.pole=Entry(self,highlightcolor="BLUE",textvariable=self.Tab,justify=RIGHT,width=WLista[icol])
        self.pole.grid(column=icol,row=irow+1)
        self.pole.insert(0,DefaultValue)
        self.FieldList.append(self.Tab)
        return self.Tab

ETab().mainloop()

-----------------------------------------------------------------

This script connects all numbers in my data-file with Entry Widget, but
the results are:

177
0 16
1 PY_VAR0
2 PY_VAR1
3 PY_VAR2
...
174 PY_VAR173
175 PY_VAR174
176 PY_VAR175


And when I change LL into LL.get():

177
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1345, in __call__
    return self.func(*args)
  File "ETab.py", line 107, in addEntry
    print k,LL.get()
AttributeError: 'int' object has no attribute 'get'

What is wrong? And, how can I take the value of self.Tab?

Sorry for my English.

M.S.







More information about the Python-list mailing list