0

everybody, I am having problems getting the data out of all my entries, when I try to execute the program it runs but will not give me the information I require it to actually work.

I the problems could be in the get() method of tkinter or any idea where the problem is in the code? I am actually new in this, I have like a month now programming.

#Importing all files 

from tkinter import *
import tkinter as tk
import os

#The command we will use to close the window

def destroy():
    top.destroy()

#This is the text we want to display

def texto():
    greets = ("Welcome " + str(Name) + "\n ")
    contact1 = ("We will contact you to " + str(Email) + "\n ")
    contact2 = ("If not possible to reach you, we will try with your phone number: " + str(Phone) + "\n ")
    contact3 = ("Your desired salary: " + str(Salary) + " will be taken in count \n ")
    contact4 = ("This information will be linked to your ID: " + str(ID) + " in our system \n ")
    return greets, contact1, contact2, contact3, contact4

#Function created to active the text once the information is filled

def activar():
    #Displaying the text in another window
    window = tk.Tk()
    window.title("Application submitted")
    Result = tk.Label(window, text = texto)
    Result.pack()

#Creating the window

top = tk.Tk()

#Size of the window
  
top.geometry("400x300")

#Title of the previous window

top.title("Application form")

#Labels of the window

greeting = tk.Label(top, text = "Please enter the information asked for below"). place(x =30,y = 10)
  
name = tk.Label(top, text = "Name").place(x = 30,y = 50)  
  
email = tk.Label(top, text = "Email").place(x = 30, y = 90)  
  
phone_number = tk.Label(top, text = "Phone Number").place(x = 30, y = 130)

salary = tk.Label(top, text = "Expected salary").place(x = 30, y = 170)

identification = tk.Label(top, text= "National certified ID").place(x = 30,y = 210)

#Botton of the window 
  
submit = tk.Button(top, text = "Submit",activebackground = "pink", activeforeground = "blue", command= activar).place(x = 320, y = 250)

#Entries
  
e1 = tk.Entry(top)
e1.place(x = 80, y = 50)  
e2 = tk.Entry(top)
e2.place(x = 80, y = 90)  
e3 = tk.Entry(top)
e3.place(x = 120, y = 130)
e4 = tk.Entry(top)
e4.place(x = 120, y = 170)
e5 = tk.Entry(top)
e5.place(x = 160, y = 210)

#Getting the information of each entry

Name = e1.get()
Email = e2.get()
Phone = e3.get()
Salary = e4.get()
ID = e5.get()

#Executing the window

top.mainloop()
Miguel Estrada
  • 31
  • 1
  • 1
  • 8
  • See https://stackoverflow.com/questions/35662844/python-tkinter-entry-get – LeoMurillo Mar 23 '20 at 23:47
  • 1
    You called `.get()` on all of your Entries *immediately* after creating them - all of those strings are going to be empty, what else could they possibly be at that point in time? You need to to this inside your Button's command function, intstead. – jasonharper Mar 23 '20 at 23:48

2 Answers2

1

After doing some research it is actually working now!! Thanks for all the answers you gave so quickly!

#Importing all modules

from tkinter import *
import tkinter as tk
import os

#This is the text we want to display

def texto():
    greets = ("Welcome " + str(Name) + "\n ")
    contact1 = ("We will contact you to " + str(Email) + "\n ")
    contact2 = ("If not possible to reach you, we will try with your phone number: " + str(Phone) + "\n ")
    contact3 = ("Your desired salary: " + str(Salary) + " will be taken in count \n ")
    contact4 = ("This information will be linked to your ID: " + str(ID) + " in our system \n ")
    return greets + contact1 + contact2 + contact3 + contact4

#Function created to active the text once the information is filled

def activar():
    #Displaying the text in this same window
    window = tk.Tk()
    window.geometry("200x200")
    window.title("Application submitted")
    Result = tk.Label(window, text = texto())
    Result.pack()

#Get values of the entries

def get_values():
    global Name
    global Email
    global Phone
    global Salary
    global ID
    Name = String1.get()
    Email = String2.get()
    Phone = String3.get()
    Salary = String4.get()
    ID = String5.get()
    activar()

#Creating the window

top = tk.Tk()

#Size of the window
  
top.geometry("400x300")

#Title of the previous window

top.title("Application form")

#Labels of the window

greeting = tk.Label(top, text = "Please enter the information asked for below"). place(x =30,y = 10)
  
name = tk.Label(top, text = "Name").place(x = 30,y = 50)  
  
email = tk.Label(top, text = "Email").place(x = 30, y = 90)  
  
phone_number = tk.Label(top, text = "Phone Number").place(x = 30, y = 130)

salary = tk.Label(top, text = "Expected salary").place(x = 30, y = 170)

identification = tk.Label(top, text= "National certified ID").place(x = 30,y = 210)

#Botton of the window 
  
submit = tk.Button(top, text = "Submit", fg = 'red',activebackground = "pink", activeforeground = "blue", command= get_values).place(x = 320, y = 250)

#Strings of each entry

String1 = tk.StringVar(top)
String2 = tk.StringVar(top)
String3 = tk.StringVar(top)
String4 = tk.StringVar(top)
String5 = tk.StringVar(top)

#Entries
  
e1 = tk.Entry(top, textvariable = String1)
e1.place(x = 160, y = 50)  
e2 = tk.Entry(top, textvariable = String2)
e2.place(x = 160, y = 90)  
e3 = tk.Entry(top, textvariable = String3)
e3.place(x = 160, y = 130)
e4 = tk.Entry(top, textvariable = String4)
e4.place(x = 160, y = 170)
e5 = tk.Entry(top, textvariable = String5)
e5.place(x = 160, y = 210)

#Executing the window

top.mainloop()
Miguel Estrada
  • 31
  • 1
  • 1
  • 8
0

On line 34, the texto function should be called with parentheses like this:

Result = tk.Label(window, text = texto ())

Then, your assignment to Name, Email, etc should be inside the texto function.

bashBedlam
  • 1,402
  • 1
  • 7
  • 11