newbie question, but please i need help
i just started learning gui programming on python, been getting this error on a code am writing concerning uising the get() method to read an integer from my entry box

from Tkinter import *
root=Tk()
var=StringVar()
label=Label(root, textvariable=var, relief=RAISED)
var.set("converter")
label.pack()
L1=Label(text="x:")
L1.pack(side= LEFT)
E1=Entry(bd=5)
E1.pack()
content =int(E1.get())
import Tkinter
def m_km(content):
    km=content/1000
    tkMessageBox.showinfo("Answer" , "%d km" %(km))
B=Tkinter.Button(text="metres to kilometres", command= m_km)
B.pack(side= RIGHT)
mainloop()

You are trying to get integer from the box even it has not yet been entered. You are reimporting Tkinter, even you imported it all to main namespace in the beginning.

Mildly modified so it will actually work ...

from Tkinter import *
import tkMessageBox

def m_km():
    content = int(E1.get())
    # force floating point division 
    km = content/1000.0  
    #print(km)  # test
    tkMessageBox.showinfo("Answer" , "%f km" % (km))

root=Tk()

label = Label(root, text="converter", relief=RAISED)
label.pack()

E1 = Entry(bd=5)
E1.pack()
E1.focus()

L1 = Label(text="x:")
L1.pack(side=LEFT)
B = Button(text="metres to kilometres", command=m_km)
B.pack(side=RIGHT)

mainloop()

Note: capitalized variable names by style convention are used for class names

thanks so much guys,i got it but due to some reasons ive not been able to login to update.i've even gone up to the stage of converting it to exe and compiling it(my first)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.