tags:

views:

367

answers:

1

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)
+1  A: 

On line 94 in F:\JavaWorkspace\Test\src\gui_geo_location.py, you're using self.entryVariable but that object does not have an entryVariable attribute.

You need to show the __init__ method of your class and any class constants so we can see if you really don't define entryVariable, or if there is something else at work.

EDIT: Based on your __init__, it seems you haven't defined entryVariable anywhere. Try adding:

self.entryVariable = Tkinter.StringVar()

to your __init__ method. See this page for more information.

Nick Presta
Hi..I attached my __init() method .. but couldnt figure it out the problem!..:(
rahman.bd
Thanks Nick..Its works!
rahman.bd