Recuperer la valeur d'un entry en Python

Fermé
lttl60 - Modifié par Whismeril le 28/01/2015 à 22:36
 Utilisateur anonyme - 28 avril 2015 à 19:08
Bonjour

voila plusieur jour que je cherche comment recuperer la valeur d'un entry sans resultas .
ci desous mon code .

Merci davance pour vos reponce

# -*-coding:Latin-1 -*

from tkinter import *





fenetre= Tk ()

fenetre.geometry("500x500")






nomLabel= Label(fenetre, text="Nom :").place(x=0, y=5)
nomEntry = Entry (fenetre).place(x=40, y=5)# entrer a recupere
# nomEntryVar= "troubat"










preNomLabel= Label(fenetre, text="Présnom :").place(x=0, y=30)
preNomEntry = Entry (fenetre).place(x=60, y=30)# entrer a recupere
# preNomEntryVar= "ludovic"


FrameResulta= Frame(fenetre, bg="White", borderwidth=2, relief=GROOVE).place(x=3, y=60, width=350, height=300)

FrameLabelMail= Label(FrameResulta, text="Vatre Mail :",bg="White").place(x=5, y=65)


FrameLabelNomUtilisateurDomaine= Label(FrameResulta, text= "Domaine et Nom Utilisateur:", bg="White").place(x=5, y=110)


FrameLabelNomUtilisateur= Label(FrameResulta, text= "nom utilisateur:", bg="White").place(x=5, y=155)


FrameLabelDomaine= Label(FrameResulta, text= "Domaine:",bg="White").place(x=5, y=200)


FrameLabelServeur= Label(FrameResulta, text= "serveur:",bg="White").place(x=5, y=245)



def definition ():
 nomEntryVarCoup = str(nomEntry.get()) [:6]
 preNomEntryVarCoup= str(preNomEntry.get) [:2]

 print (str(omEntry.get())) 
 print (str(preNomEntry.get()))
 
 mailDef= Label(FrameResulta, text= nomEntry.get()+"."+preNomEntry.get()+"@ville-malakoff.fr", bg="white").place(x=5, y=80)
 DomaineNom= Label(FrameResulta, text="intra\\"+nomEntryVarCoup+preNomEntryVarCoup, bg="White").place(x=5, y=125)
 NomUtilisateur= Label(FrameResulta, text= nomEntryVarCoup+preNomEntryVarCoup, bg= "White").place(x=5, y=170)
 Domaine= Label(FrameResulta, text="intra", bg="White").place(x=5, y=215)
 Serveur= Label(FrameResulta, text= "mail.ville-malakoff.fr", bg= "White").place(x=5, y=260)
 



 
ButtonValider= Button(fenetre, text= "Valider", command= definition).place(x=50, y=450)

fenetre.mainloop ()


le message suivent safiche:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "P:\Mes document\Mes Programmes\Python\prog (.py .pyw)\mail ville.py", line 55, in definition
nomEntryVarCoup = str(nomEntry.get()) [:6]
AttributeError: 'NoneType' object has no attribute 'get'

merci de votre aide

EDIT: Spécification du langage dans la coloration syntaxique.
A voir également:

1 réponse

Utilisateur anonyme
28 avril 2015 à 19:08
Utilise la méthode .bind("Touche",fonction) (attention, fonction doit avoir comme paramètre unique : event).

from tkinter import *

root=Tk()

def lecture(event):
    print(e.get())

e=Entry(root)
e.bind("<Return>",lecture)
e.pack()


root.mainloop()
0