Get content of Tkinter Entry widget
I am creating an application and I want to use the entered values ββin the login widgets in the GUI.
How to get typed input from Tkinter login widget?
root = Tk() ... entry = Entry(root) entry.pack() root.mainloop()
+3
enginefree
source
to share
3 answers
You need to do two things: store the link to the widget and then use a method get()
to get the string.
Here's an example:
self.entry = Entry(...)
...
print("the text is", self.entry.get())
+10
Bryan oakley
source
to share
Here's an example:
import tkinter as tk
class SampleApp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.entry = tk.Entry(self)
self.button = tk.Button(self, text="Get", command=self.on_button)
self.button.pack()
self.entry.pack()
def on_button(self):
print(self.entry.get())
w = SampleApp()
w.mainloop()
+2
Someones_Name
source
to share
First, declare a variable of the required type. For example, an integer:
var = IntVar ()
Then:
entry = Entry (root, textvariable = var )
entry.pack ()
user_input = var.get ()
root.mainloop ()
Hope it helps.
0
Aleksandar Krumov
source
to share