Python Forum
[Tkinter] how to get the entry information using Entry.get() ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] how to get the entry information using Entry.get() ?
#1
Hello, I have a problem. I would like to retrieve the information in my Entry to put in list_info. thank you in advance.
from tkinter import *

# reglages
width = 800
height = 600
couleur = (48, 47, 47)
couleurmes = (113, 113, 113)


class Appli():
    def __init__(self):
        self.fenetre = Tk()
        self.fenetre.geometry("1000x600")
        self.fenetre.title('Appli')
        self.fenetre.configure(background="#cecece")
        self.fenetre.configure(highlightbackground="#cecece")
        self.fenetre.configure(borderwidth="1")
        self.fenetre.configure(relief="sunken")
        self.fenetre.attributes('-alpha', 0.98)
        self.objet()


    liste_Info = []


    def objet(self):

        self.listeF = ['NOM :', 'PRENOM :', 'ADRESSE :', 'N° TELE :', 'MAIL :' ]
        self.liste_Info = []


        R_span = 2
        R_pady = 70

        # graphique creation

        for x in self.listeF:

            global  entree

            x = Label(self.fenetre, text=x, bg='#cecece', fg='black')
            x.grid(row=1, column=2, rowspan =  R_span, pady = R_pady, sticky = W)
            x = Entry(self.fenetre, bg='black', fg='white')
            x.grid(row=1, column=3, rowspan=R_span, pady=R_pady, sticky = NW)

            print(x)
            entree = x.get()
            R_span += 1
            R_pady +=50


        self.lab_mes = Label(self.fenetre, text='MESSAGE : ', bg='#cecece', fg='black')
        self.lab_mes.grid(row=1, column=4, padx=40, rowspan = 2, sticky = W)


        self.MES = Entry(self.fenetre, bg='black', fg='white')
        self.MES.grid(row=2, column=4, padx=40, rowspan=2, ipady = 40, sticky = W)


        self.bouton = Button(self.fenetre, text='Valider', command=self.Entree_Get())
        self.bouton.grid(row=4, column=4,padx=40,sticky = NE)


        self.canphoto = Canvas(self.fenetre, width=165, height=222, bg='dark grey')
        self.canphoto.grid(row=1, column=1, rowspan=4, padx=20, pady=70,sticky = W)

    def Entree_Get(self):
        self.liste_Info.append(entree)
        print(self.liste_Info)


application = Appli()
application.fenetre.mainloop()
Reply
#2
Does Entry.get() not work? In this case, self.MES.get()
Reply
#3
You have to keep a reference to each individual Entry, in this case x. Each pass through the for overlays the previous x, so it no longer exists. So, using a dictionary below, so you can store everything in one container

## NOT tested - don't have time
## post back if there are problems

        self.entry_dict={}
        for x in self.listeF:
 
            ##global  entree
 
            ## don't have to keep a reference to the Label
            ## since it isn't accessed anywhere else
            Label(self.fenetre, text=x, bg='#cecece',
                  fg='black').grid(row=1, column=2,
                  rowspan =  R_span, pady = R_pady, sticky = W)
            y = Entry(self.fenetre, bg='black', fg='white')
            y.grid(row=1, column=3, rowspan=R_span, pady=R_pady, sticky = NW)
            self.entry_dict[x]=y
        print("entry_dict", self.entry_dict) ## self.listeF item --> tkinter instance

    def Entree_Get(self):
        for x in self.listeF:  ## read the dict in this order
            print(x, self.entry_dict[x].get()) 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: could not convert string to float: '' fron Entry Widget russellm44 5 492 Mar-06-2024, 08:42 PM
Last Post: russellm44
  [Tkinter] entry widget DPaul 5 1,433 Jul-28-2023, 02:31 PM
Last Post: deanhystad
  [PyGUI] Invalid command error with Entry object eliqm 8 2,027 May-18-2023, 10:14 PM
Last Post: eliqm
  Get string from entry and use it in another script amdi40 1 1,345 Jan-26-2022, 07:33 PM
Last Post: Larz60+
  [Tkinter] Making entry global in tkinter with multiprocessing luckyingermany 2 2,284 Jan-21-2022, 03:46 PM
Last Post: deanhystad
  [Tkinter] How Does Entry Verification Work? gw1500se 2 1,591 Nov-17-2021, 02:16 PM
Last Post: gw1500se
  [Tkinter] define entry via class on a loop drSlump 9 3,375 Oct-27-2021, 05:01 PM
Last Post: deanhystad
  Tkinter Exit Code based on Entry Widget Nu2Python 6 2,875 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  [Tkinter] Update variable using tkinter entry methon drSlump 6 5,093 Oct-15-2021, 08:01 AM
Last Post: drSlump
  Tkinter | entry output. Sap2ch 1 1,950 Sep-25-2021, 12:38 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020