Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] getting Entry text
#1
hello everybody. first post here Smile

i'm having trouble to get the text value inside an Entry box. So, i created this small example that shows up the problem:

import tkinter as tk

root = tk.Tk()
label = tk.Label(root, text="Entry Box")
label.pack()
entry = tk.Entry(root)
entry.pack()
button = tk.Button(root, text="Print", command=print(entry.get()))
button.pack()

root.mainloop()
why doesn't it print the value entered by the user? do i have to update the entry box somehow?
thanks in advance :)
Quote
#2
u need define the function first
like this.
import tkinter as tk
class Print:
    def __init__(self):
        Value = entry.get()
        print(Value)
root = tk.Tk()
label = tk.Label(root, text="Entry Box")
label.pack()
entry = tk.Entry(root)
entry.pack()
button = tk.Button(root, text="Print", command=Print)
button.pack()

root.mainloop()
Quote
#3
See the following similar thread.
https://python-forum.io/Thread-Tkinter-N...t-updating
Quote
#4
oh, i tought print coubl be used as a function
thanks! Big Grin
Quote
#5
I believe print can be used as a function, but I think you were having the same issue I was having. At the time you click the button, the print function runs, but the get() function has not taken in the entry yet cause you are calling it at the same time. So you are getting a null value. So by separating out the get function, you are getting the information from the entry and then printing it.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] how to get the entry information using Entry.get() ? SamyPyth 2 618 Mar-18-2019, 05:36 PM
Last Post: woooee
  [WxPython] bind label and entry text with return key metulburr 1 776 Aug-14-2018, 10:02 PM
Last Post: metulburr
  [Tkinter] Hide text in entry box when i click on it. MeeranRizvi 1 4,871 Jan-25-2017, 10:38 AM
Last Post: MeeranRizvi
  [Tkinter] Entry widget : unable to get the text entered dlemper 2 8,820 Oct-11-2016, 12:32 AM
Last Post: dlemper

Forum Jump:


Users browsing this thread: 1 Guest(s)