PDA

Visualizza la versione completa : [PYTHON] Errore: object has no attribute


arna98
25-01-2012, 16:08
from Tkinter import *
from tkMessageBox import *
import os,sys,time
from math import sqrt
#funzioni di sistema
def materiali_tendina_funz(ev):
select=list_materiale.get(list_materiale.curselect ion())
list_materiale.configure(bg=select)
#Variabili fiss
kgottone=1
kgrame=1
kgalluminio=1
kgacciaio=1
kgferro=1
kgcorten=1
tmptornitura=1
tmpsmerigliatura=1
tmpfresatura=1
tmpverniciatura=1
tmpcesoiatura=1
tmpsaldatura=1
tmppiegatura=1
tmptaglio=1
tmpsatinatura=1
#Funzioni di calcolo
def calcola():
a=kgottone*ottone.get()
def calcolatrice():
window_c=Tk()
window_c.title("ARITMETICA-MEGA CALCULATOR")
window_c.resizable(True,True)
window_c['background']="White"
Title=Label(window_c,text="SOMMA",bg="White",fg="Red").grid(row=0,column=0)
Final_Label=Label(window_c,text='0',bg="Green",width=20).grid(row=7,column=0,padx=10,pady=10)
Title=Label(window_c,text="SOTTRAZIONE",bg="White",fg="Red").grid(row=0,column=1)
Final_Label=Label(window_c,text='0',bg="Green",width=20).grid(row=7,column=1,padx=10,pady=10)
Title=Label(window_c,text="MOLTIPLICAZIONE",bg="White",fg="Red").grid(row=0,column=2)
Final_Label=Label(window_c,text='0',bg="Green",width=20).grid(row=7,column=2,padx=10,pady=10)
Title=Label(window_c,text="DIVISIONE",bg="White",fg="Red").grid(row=0,column=3)
Final_Label=Label(window_c,text='0',bg="Green",width=20).grid(row=7,column=3,padx=10,pady=10)
Tiltle=Label(window_c,text="RADICE",bg="White",fg="Red").grid(row=8,column=0)
Final_Label=Label(window_c,text='0',bg="Green",width=20).grid(row=14,column=0,padx=10,pady=10)
Tiltle=Label(window_c,text="ELEVAZIONE A POTENZA",bg="White",fg="Red").grid(row=8,column=1)
Final_Label=Label(window_c,text='0',bg="Green",width=20).grid(row=14,column=1,padx=10,pady=10)
Esci=Button(text="Esci",command=esci).grid(row=14,column=3,padx=10,pady=1 0)
x_add=IntVar()
y_add=IntVar()
add1=Entry(window_c,textvariable=x_add,width=30).g rid(row=1)
add2=Entry(window_c,textvariable=y_add,width=30).g rid(row=2)
Somma=Button(window_c,text="Somma",command=somma).grid(column=0,row=3,padx=5,pady=5)
x_sot=IntVar()
y_sot=IntVar()
sot1=Entry(window_c,textvariable=x_sot,width=30).g rid(row=1,column=1)
sot2=Entry(window_c,textvariable=y_sot,width=30).g rid(row=2,column=1)
Sottrai=Button(window_c,text="Sottrai",command=sottrazione).grid(column=1,row=3,padx=5,p ady=5)
x_mol=IntVar()
y_mol=IntVar()
sot1=Entry(window_c,textvariable=x_mol,width=30).g rid(row=1,column=2)
sot2=Entry(window_c,textvariable=y_mol,width=30).g rid(row=2,column=2)
Sottrai=Button(window_c,text="Moltiplica",command=moltiplicazione).grid(column=2,row=3,padx =5,pady=5)
x_div=IntVar()
y_div=IntVar()
sot1=Entry(window_c,textvariable=x_div,width=30).g rid(row=1,column=3)
sot2=Entry(window_c,textvariable=y_div,width=30).g rid(row=2,column=3)
Sottrai=Button(window_c,text="Dividi",command=divisione).grid(column=3,row=3,padx=5,pad y=5)
x_rad=IntVar()
rad=Entry(window_c,textvariable=x_rad,width=30).gr id(row=9,column=0)
rad_space=Label(window_c,window_father,text=" ",bg="White",fg="White").grid(row=10,column=0)
Radicie=Button(window_c,text="Radice",command=radice).grid(column=0,row=11,padx=5,pady= 5)
x_pot=IntVar()
y_pot=IntVar()
pot1=Entry(window_c,textvariable=x_pot,width=30).g rid(row=9,column=1)
pot2=Entry(window_c,textvariable=y_pot,width=30).g rid(row=10,column=1)
eleva_a_Potenza=Button(window_c,text="Eleva a potenza",command=potenza).grid(column=1,row=11,padx=5,pady =5)
window_c.mainloop()



def somma():
a=x_add.get()+y_add.get()
result=Label(window_c,text=a,width=20,bg="Green").grid(row=7,column=0)
def sottrazione():
b=x_sot.get()-y_sot.get()
result=Label(window_c,text=b,width=20,bg="Green").grid(row=7,column=1)
def moltiplicazione():
c=x_mol.get()*y_mol.get()
result=Label(window_c,text=c,width=20,bg="Green").grid(row=7,column=2)
def divisione():
try:
d=x_div.get()/y_div.get()
result=Label(window_c,text=d,width=20,bg="Green").grid(row=7,column=3)
except:
showerror("ERRORE!","IMPOSSIBILE DIVIDERE UN NUMERO PER 0")
def radice():
e=sqrt(x_rad.get())
result=Label(window_c,text=e,width=20,bg="Green").grid(row=14,column=0)
def potenza():
f=x_pot.get()**y_pot.get()
result=Label(window_c,text=f,width=20,bg="Green").grid(row=14,column=1)
def esci():
window_c.destroy()




#Creazione finestra padre
window_father=Tk()
window_father.title("Calcolatore di preventivi Arnaboldi Luigi & C. s.n.c.")
window_father.geometry("1270x770")
window_father.resizable(True,True)
window_father['background']="White"
tab=Label(text="Materliale ---->",width=20,bg="Green").grid(row=0,column=0)
tab=Label(text="Quantita'(in kg) ---->",width=20,bg="Green").grid(row=1,column=0)
tab=Label(text="Materliale ---->",width=20,bg="Green").grid(row=2,column=0)
tab=Label(text="Quantita'(in kg) ---->",width=20,bg="Green").grid(row=3,column=0)
tit_ottone=Label(text="OTTONE",bg="White",fg="Red",width=20).grid(row=2,column=1)
ottone=IntVar()
ottone=Entry(textvariable=ottone,width=30).grid(ro w=3,column=1)
tit_rame=Label(text="RAME",bg="White",fg="Red",width=20).grid(row=0,column=1)
rame=IntVar()
rame=Entry(textvariable=rame,width=30).grid(row=1, column=1)
tit_aluuminio=Label(text="ALLUMINIO",bg="White",fg="Red",width=20).grid(row=0,column=2)
alluminio=IntVar()
alluminio=Entry(textvariable=alluminio,width=30).g rid(row=1,column=2)
tit_ferro=Label(text="FERRO",bg="White",fg="Red",width=20).grid(row=0,column=3)
ferro=IntVar()
ferro=Entry(textvariable=ferro,width=30).grid(row= 1,column=3)
tit_acciaio=Label(text="ACCIAIO INOX",bg="White",fg="Red",width=20).grid(row=0,column=4)
acciaio=IntVar()
acciaio=Entry(textvariable=acciaio,width=30).grid( row=1,column=4)
tit_corten=Label(text="CORTEN",bg="White",fg="Red",width=20).grid(row=2,column=2)
corten=IntVar()
corten=Entry(textvariable=corten,width=30).grid(ro w=3,column=2)
tit_altro=Label(text="ALTRO --->",bg="White",fg="Red",width=20).grid(row=2,column=4)
altro=IntVar()
altro=Entry(textvariable=altro,width=30).grid(row= 3,column=4)
tit_kgaltro=Label(text="Immettere l' /kg di ALTRO",bg="White",fg="Red",width=20).grid(row=4,column=4)
kgaltro=IntVar()
altro=Entry(textvariable=kgaltro,width=30).grid(ro w=5,column=4)
tab=Label(text="Lavorazioni esterne ---->",width=20,bg="Green").grid(row=6,column=0)
tab=Label(text="Valore(in ) ---->",width=20,bg="Green").grid(row=7,column=0)
tab=Label(text="Aumento(in %) ---->",width=20,bg="Green").grid(row=8,column=0)
tit_ottone=Label(text="LAVORAZIONE ESTERNA 1",bg="White",fg="Red",width=20).grid(row=6,column=1)
lav_est1=IntVar()
ottone=Entry(textvariable=lav_est1,width=30).grid( row=7,column=1)
tit_rame=Label(text="LAVORAZIONE ESTERNA 2",bg="White",fg="Red",width=20).grid(row=6,column=2)
lav_est2=IntVar()
rame=Entry(textvariable=lav_est2,width=30).grid(ro w=7,column=2)
tit_aluuminio=Label(text="LAVORAZIONE ESTERNA 3",bg="White",fg="Red",width=20).grid(row=6,column=3)
lav_est3=IntVar()
alluminio=Entry(textvariable=lav_est3,width=30).gr id(row=7,column=3)
tit_ferro=Label(text="LAVORAZIONE ESTERNA 4",bg="White",fg="Red",width=20).grid(row=6,column=4)
lav_est4=IntVar()
ferro=Entry(textvariable=lav_est4,width=30).grid(r ow=7,column=4)
p_est1=IntVar()
ottone=Entry(textvariable=p_est1,width=30).grid(ro w=8,column=1)
p_est2=IntVar()
rame=Entry(textvariable=p_est2,width=30).grid(row= 8,column=2)
p_est3=IntVar()
alluminio=Entry(textvariable=p_est3,width=30).grid (row=8,column=3)
p_est4=IntVar()
ferro=Entry(textvariable=p_est4,width=30).grid(row =8,column=4)
tab=Label(text="Lavorazione interna ---->",width=20,bg="Green").grid(row=9,column=0)
tab=Label(text="Tempo(in minuti) ---->",width=20,bg="Green").grid(row=10,column=0)
tab=Label(text="Lavorazione interna ---->",width=20,bg="Green").grid(row=11,column=0)
tab=Label(text="Tempo(in minuti) ---->",width=20,bg="Green").grid(row=12,column=0)
tit_ottone=Label(text="TORNITURA",bg="White",fg="Red",width=20).grid(row=11,column=1)
tornitura=IntVar()
ottone=Entry(textvariable=tornitura,width=30).grid (row=12,column=1)
tit_rame=Label(text="SMERIGLIATURA",bg="White",fg="Red",width=20).grid(row=9,column=1)
smerigliatura=IntVar()
rame=Entry(textvariable=smerigliatura,width=30).gr id(row=10,column=1)
tit_aluuminio=Label(text="FRESATURA",bg="White",fg="Red",width=20).grid(row=9,column=2)
fresatura=StringVar()
alluminio=Entry(textvariable=fresatura,width=30).g rid(row=10,column=2)
tit_ferro=Label(text="VERNICIATURA",bg="White",fg="Red",width=20).grid(row=9,column=3)
verniciatura=IntVar()
ferro=Entry(textvariable=verniciatura,width=30).gr id(row=10,column=3)
tit_acciaio=Label(text="CESOIATURA",bg="White",fg="Red",width=20).grid(row=9,column=4)
cesoiatura=IntVar()
acciaio=Entry(textvariable=cesoiatura,width=30).gr id(row=10,column=4)
tit_corten=Label(text="SALDATURA",bg="White",fg="Red",width=20).grid(row=11,column=2)
saldatura=IntVar()
corten=Entry(textvariable=saldatura,width=30).grid (row=12,column=2)
tit_ottone=Label(text="PIEGATURA",bg="White",fg="Red",width=20).grid(row=11,column=3)
piegatura=IntVar()
ottone=Entry(textvariable=piegatura,width=30).grid (row=12,column=3)
tit_rame=Label(text="TAGLIO",bg="White",fg="Red",width=20).grid(row=13,column=1)
taglio=IntVar()
rame=Entry(textvariable=taglio,width=30).grid(row= 14,column=1)
tit_aluuminio=Label(text="SATINATURA",bg="White",fg="Red",width=20).grid(row=13,column=2)
satinatura=IntVar()
alluminio=Entry(textvariable=satinatura,width=30). grid(row=14,column=2)
tit_altro=Label(text="ALTRO --->",bg="White",fg="Red",width=20).grid(row=11,column=4)
altro_lav=IntVar()
altro=Entry(textvariable=altro_lav,width=30).grid( row=12,column=4)
tit_kgaltro=Label(text="/minuti di ALTRO",bg="White",fg="Red",width=20).grid(row=13,column=4)
tempoaltro=IntVar()
altro=Entry(textvariable=tempoaltro,width=30).grid (row=14,column=4)
calcola=Button(text="c",command=calcola).grid(row=16,column=0)
window_father.mainloop()


sto facendo un programma per preventivi, ma quando provo ad eseguire il programma cliccando sul tasto "c" , mi dice che:


Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
File "/home/luca/Scrivania/calcolatore di preventivi.py", line 27, in calcola
a=kgottone*ottone.get()
AttributeError: 'NoneType' object has no attribute 'get'

Grazie

esattore
04-02-2012, 13:44
Il problema che utilizzi la variabile ottone nella funzione calcola() senza prima averla dichiarata.
Modifica la funzione in questo modo;

def calcola(ottone):
in modo che quando la chiami gli passi la variabile dichiarata.
Ciao

arna98
19-05-2012, 13:48
no non funziona allo stesso!!!

Loading