Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] how to get the entry information using Entry.get() ?
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.attributes('-alpha', 0.98)

    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)

            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):

application = Appli()
Yoriz wrote Mar-16-2019, 12:45 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Does Entry.get() not work? In this case, self.MES.get()
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

        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)
        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()) 

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  The coordinates of the Entry widget (canvas) when moving berckut72 8 189 Jan-07-2020, 09:26 AM
Last Post: berckut72
  [Tkinter] Setting Binding to Entry created with a loop? p_hobbs 1 133 Nov-25-2019, 10:29 AM
Last Post: Larz60+
  Newbie question with Tkinter Entry mariolopes 2 193 Oct-12-2019, 11:02 PM
Last Post: Larz60+
  [Tkinter] Accessing Entry with get Function nexgenskydiver 1 197 Oct-07-2019, 09:21 AM
Last Post: wuf
  [Tkinter] Entry widget to variable Zeiphar 4 293 Sep-21-2019, 05:41 AM
Last Post: Zeiphar
  Entry in textdocument Piethon 6 300 Sep-11-2019, 06:00 PM
Last Post: jefsummers
  [Tkinter] How to bind an event when enter is pressed on a Entry control? Michael4 4 338 Aug-29-2019, 10:11 PM
Last Post: Michael4
  [Tkinter] Inserting numbers into entry box in a widget richard13 1 494 Aug-11-2019, 11:37 AM
Last Post: Yoriz
  [PyQt] Collect entry from textline Widget via UI file mart79 3 337 Aug-05-2019, 01:40 PM
Last Post: Denni
  [Tkinter] Returning Entry as a Label ashleyrfm94 2 329 Jul-22-2019, 04:47 PM
Last Post: Yoriz

Forum Jump:

Users browsing this thread: 1 Guest(s)