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",r elief=RAISED)
self.master.tit le('Data for grid generation')
self.grid()
ELista=["nr","Egde","nC ell","nFun","P" ,"Q","Metoda"," WBTyp","Left"," Right","sigma"]
for icol in range(len(EList a)):
self.Etykieta(i col,irow=0,ETex t=ELista[icol])
f=open('ETab_H1 .dan', 'r');
self.c=f.readli ne()
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.applyBotto n = Button(self,tex t="Apply",comma nd=self.addEntr y)
self.applyBotto n.grid(column=d l-2,row=c1+1)
self.quitButton = Button(self, text="Quit",com mand=self.quit)
self.quitButton .grid(column=dl-1,row=c1+1)
def addEntry(self):
nElem=len(self. FieldList)
print nElem
ff=open('ETab_H 1.spr', 'w');
ff.write(self.c )
LL=StringVar()
for k in range(nElem):
LL=self.FieldLi st[k]
print k,LL
ff.close()
def Etykieta(self,i col,irow,EText) :
lab=Label(self, text=EText)
lab.grid(column =icol,row=irow)
return
def Pola(self,k,ico l,irow,DefaultV alue):
self.Tab=String Var()
WLista=[5,5,5,5,10,10,1 0,10,10,10,10]
self.pole=Entry (self,highlight color="BLUE",te xtvariable=self .Tab,justify=RI GHT,width=WList a[icol])
self.pole.grid( column=icol,row =irow+1)
self.pole.inser t(0,DefaultValu e)
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.
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",r elief=RAISED)
self.master.tit le('Data for grid generation')
self.grid()
ELista=["nr","Egde","nC ell","nFun","P" ,"Q","Metoda"," WBTyp","Left"," Right","sigma"]
for icol in range(len(EList a)):
self.Etykieta(i col,irow=0,ETex t=ELista[icol])
f=open('ETab_H1 .dan', 'r');
self.c=f.readli ne()
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.applyBotto n = Button(self,tex t="Apply",comma nd=self.addEntr y)
self.applyBotto n.grid(column=d l-2,row=c1+1)
self.quitButton = Button(self, text="Quit",com mand=self.quit)
self.quitButton .grid(column=dl-1,row=c1+1)
def addEntry(self):
nElem=len(self. FieldList)
print nElem
ff=open('ETab_H 1.spr', 'w');
ff.write(self.c )
LL=StringVar()
for k in range(nElem):
LL=self.FieldLi st[k]
print k,LL
ff.close()
def Etykieta(self,i col,irow,EText) :
lab=Label(self, text=EText)
lab.grid(column =icol,row=irow)
return
def Pola(self,k,ico l,irow,DefaultV alue):
self.Tab=String Var()
WLista=[5,5,5,5,10,10,1 0,10,10,10,10]
self.pole=Entry (self,highlight color="BLUE",te xtvariable=self .Tab,justify=RI GHT,width=WList a[icol])
self.pole.grid( column=icol,row =irow+1)
self.pole.inser t(0,DefaultValu e)
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.