Reputation: 3
I apologies because I'm a new user for python tkinter. It is possible to export data inputted with Entry function? Currently the code works, but the value is not present in the "e1" output. Thanks in advance
try:
import Tkinter as tk
except:
import tkinter as tk
class Test():
def __init__(self):
self.root = tk.Tk()
self.root.geometry('100x50')
e1 = tk.Entry(self.root)
e1.pack()
self.e1 = e1.get()
button = tk.Button(self.root,
text = 'Quit and take out values',
command=self.quit)
button.pack()
self.root.mainloop()
def quit(self):
self.root.destroy()
app = Test()
print(app.e1)
Upvotes: 0
Views: 132
Reputation: 46811
You call e1.get()
right after e1
is created. So at that time there is nothing input and you should get an empty string.
You can get the entry value inside quit()
function, but you need to rename e1
to self.e1
:
try:
import Tkinter as tk
except:
import tkinter as tk
class Test():
def __init__(self):
self.root = tk.Tk()
self.root.geometry('100x50')
self.e1 = tk.Entry(self.root)
self.e1.pack()
button = tk.Button(self.root,
text = 'Quit and take out values',
command=self.quit)
button.pack()
self.root.mainloop()
def quit(self):
self.value = self.e1.get()
self.root.destroy()
app = Test()
print(app.value)
Upvotes: 2