Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Peter Lodri
6,757 PointsTkinter Entry get problem
Hy guys, so I've already had a script to get date by Google's Geocode API and now I try to make a GUI for it. The layout is pretty completed (more or less) but I've coudn't got around how to get the user input out of the entry field. I've put a submit button to press and then check the field, but I've got :
AttributeError: 'function' object has no attribute 'get'
Here's the full code, thanks if you check it out.
import Tkinter as tk
import tkMessageBox as mbox
from geocode import *
class Hike():
g = Geocode()
def __init__(self, master):
self.master = master
self.mainframe = tk.Frame(self.master, bg="grey")
self.mainframe.pack(fill=tk.BOTH, expand=True)
self.build_grid()
self.entry()
self.banner()
self.lang = tk.IntVar()
self.lang_box()
self.set_lang()
self.log_check()
self.location_text()
self.submit()
self.status()
self.on_button()
def build_grid(self):
self.mainframe.columnconfigure(0, weight=1)
self.mainframe.rowconfigure(1, weight=0)
self.mainframe.rowconfigure(2, weight=0)
self.mainframe.rowconfigure(3, weight=0)
self.mainframe.rowconfigure(4, weight=1)
self.mainframe.columnconfigure(1, weight=1)
def banner(self):
banner = tk.Label(
self.mainframe,
text='PyHike',
fg='red',
font=('Helvetica', 20)
)
banner.grid(
row=0, columnspan=2,
sticky='ew',
padx=10, pady=10
)
def lang_box(self):
box_frame = tk.Frame(self.mainframe)
box_frame.grid(row=1, column=0, sticky='nsew')
box_frame.columnconfigure(0, weight=1)
box_frame.columnconfigure(1, weight=1)
hu = tk.Radiobutton(
box_frame,
text='Hungarian',
variable=self.lang,
value=1,
command=self.set_lang
)
hu.grid(
row=1, column=0,
columnspan=1,
sticky='ew',
)
en = tk.Radiobutton(
box_frame,
text='English',
variable=self.lang,
value=2,
command=self.set_lang
)
en.grid(
row=1, column=1,
columnspan=1,
sticky='ew',
)
def log_check(self):
logbox = tk.Checkbutton(
self.mainframe,
text="Save log",
)
logbox.grid(
row=1, column=1,
columnspan=1,
sticky='ewsn'
)
def set_lang(self):
if self.lang.get() == 1:
print "Magyar!"
elif self.lang.get() == 2:
print "Angol!"
def location_text(self):
label = tk.Label(
self.mainframe,
text="Enter location:"
)
label.grid(
row=2, column=0,
columnspan=1,
sticky='we',
padx=5, pady=5
)
def entry(self):
entry = tk.Entry(
self.mainframe,
bd=5)
entry.grid(
row=2, column=1,
columnspan=2,
sticky='ewns',
padx=5, pady=5
)
def submit(self):
button = tk.Button(
self.mainframe,
text="Search",
width=15,
command=self.on_button
)
button.grid(
row=3, columnspan=2,
sticky='wens',
padx=5, pady=5
)
def on_button(self):
print self.entry.get
def search(self):
self.g.loc_search(self.on_button())
self.g.json_req()
print self.g.geodata()
def status(self):
status = tk.Label(
self.mainframe,
text="TEST TEST TES t TE st T est test",
bd=1,
relief=tk.SUNKEN
)
status.grid(
row=4,
columnspan=2,
sticky='wes'
)
if __name__ == '__main__':
root = tk.Tk()
Hike(root)
root.mainloop()
1 Answer
Kurt Moseley
19,309 Pointsdef entry(self):
self.entry = tk.Entry(
self.mainframe,
bd=5)
self.entry.grid(
row=2, column=1,
columnspan=2,
sticky='ewns',
padx=5, pady=5
)
Peter Lodri
6,757 PointsPeter Lodri
6,757 PointsThanks for pointing it out!