Home > other >  Tkinter returning ".!entry" instead of text contents of the Entry
Tkinter returning ".!entry" instead of text contents of the Entry

Time:04-27

I was making a program that takes and entry and returns it with tkinter and a tkinter grid, but when I tried to get the value of what was in the Entry, it didn't work!

I looked on the internet for solutions but none of them included a grid except this one:
Return values of Tkinter text entry, close GUI, but it's way too hard!

Here is my code so far:

# import tkinter module
from tkinter import *
from tkinter.ttk import *

# creating main tkinter window/toplevel
master = Tk()

# this will create a label widget
l1 = Label(master, text = "First:")
l2 = Label(master, text = "Second:")

# entry widgets, used to take entry from user
e1 = Entry(master)
e2 = Entry(master)
def input_():
    title = e1.get()
    body = e2.get()
    print(e1)
    print(e2)
# grid method to arrange labels in respective
# rows and columns as specified
l1.grid(row = 0, column = 0, sticky = W, pady = 2)
l2.grid(row = 1, column = 0, sticky = W, pady = 2)
submit = Button(master, text="Submit", command=input_)

# this will arrange entry widgets
e1.grid(row = 0, column = 1, pady = 2)
e2.grid(row = 1, column = 1, pady = 2)
submit.grid(row = 3, column = 1, pady = 2)

# infinite loop which can be terminated by keyboard
# or mouse interrupt
mainloop()

CodePudding user response:

That's probably because in the input function, you are printing

print(e1)
print(e2)

which are the Entry objects. You might have been trying to print the title and body, which are being extracted, but unused.

  • Related