Hello, I want to show my calculated output to Gui window in python.I am trying with Tkinter.But having problem to get output on Tkinter level widget.The thing is that, I am putting input data as address information in text field of Tkinter window and want latitude , longitude of that inputed address to the text label. Can anyone please help me out of this? I am just quite new to this Tkinter..
code is below:
def initialize(self):
self.grid()
self.entry = Tkinter.Entry(self)
self.entry.grid(column=0,row=0,sticky='EW')
button = Tkinter.Button(self,text=u"Get Geo information !",command=self.OnButtonClick)
button.grid(column=1,row=0)
self.labelVariable = Tkinter.StringVar()
label = Tkinter.Label(self,textvariable=self.labelVariable,
anchor="w",fg="black",bg="white")
label.grid(column=0,row=1,columnspan=2,sticky='EW')
self.grid_columnconfigure(0,weight=1)
self.resizable(True,False)
def OnButtonClick(self):
outf = open(out_file,'w')
outf_failed = open(out_file_failed,'w')
#inf = open(addr_file,'r')
inf = codecs.open(addr_file, 'r', 'iso-8859-1')
for address in inf:
#get latitude and longitude of address
data = geocode(address)
#output results and log to file
if len(data)>1:
self.labelVariable.set( self.entryVariable.get()+" (Latitude )", data['lat'] )
self.labelVariable.set( self.entryVariable.get()+" (Longitude )", data['lng'] )
outf.write(address.strip()+data['lat']+','+data['lng']+'\n')
outf.flush()
else:
self.labelVariable.set( self.entryVariable.get()+" Geocoding of '"+addr_file+"' failed with error code "+data['code'] )
outf_failed.write(address)
outf_failed.flush()
time.sleep(sleep_time)
#clean up
inf.close()
outf.close()
outf_failed.close()
if __name__ == "__main__":
app = simpleapp_tk(None)
app.title('Your Location')
app.mainloop()
And I got error :
File "F:\JavaWorkspace\Test\src\gui_geo_location.py", line 94, in OnButtonClick
self.labelVariable.set( self.entryVariable.get()+" (Latitude )", data['lat'] )
File "C:\Python25\lib\lib-tk\Tkinter.py", line 1721, in __getattr__
return getattr(self.tk, attr)
AttributeError: entryVariable
Here is my __init() method :
def init(self,parent): Tkinter.Tk.init(self,parent) self.parent = parent self.initialize()
def initialize(self):
self.grid()
self.entry = Tkinter.Entry(self)
self.entry.grid(column=0,row=0,sticky='EW')
self.entry.bind("<Return>", self.OnPressEnter)
button = Tkinter.Button(self,text=u"Get Geo information !",command=self.OnButtonClick)
button.grid(column=1,row=0)
self.labelVariable = Tkinter.StringVar()
label = Tkinter.Label(self,textvariable=self.labelVariable,
anchor="w",fg="black",bg="white")
label.grid(column=0,row=1,columnspan=2,sticky='EW')
self.grid_columnconfigure(0,weight=1)
self.resizable(True,False)