import Tkinter
class converter(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.initialize()
def initialize(self):
self.grid()
self.labelVariable = Tkinter.IntVar()
welcome = Tkinter.Label(self, textvariable=self.labelVariable, anchor="w", fg="black", bg="lightgrey")
welcome.grid(column=0, row=0, columnspan=3, sticky='EW')
self.labelVariable.set(u"Hello there. Welcome to MAKK's currency converter.")
self.entryVariable = Tkinter.StringVar()
self.entry = Tkinter.Entry(self,textvariable=self.entryVariable)
self.entry.grid(column=0, row=1, sticky='EW')
self.entry.bind("<Return>", self.OnPressEnter)
self.entryVariable.set(u"Enter currency here.")
money = self.entryVariable.set
toUSD = Tkinter.Button(self, text=u"Convert to USD", command=self.ConvertToUSD)
toUSD.grid(column=1, row=1)
toCAD = Tkinter.Button(self, text=u"Convert to CAD", command=self.ConvertToCAD)
toCAD.grid(column=2, row=1)
self.labelVariable = Tkinter.StringVar()
output = Tkinter.Label(self, textvariable=self.labelVariable, anchor="w", fg="black", bg="lightgrey")
output.grid(column=0, row=3, columnspan=3, sticky='EW')
self.labelVariable.set(u"Hello !")
self.grid_columnconfigure(0,weight=1)
self.resizable(False,False)
self.update()
self.geometry(self.geometry())
self.entry.focus_set()
self.entry.selection_range(0, Tkinter.END)
def ConvertToUSD(self):
self.labelVariable.set(self.entryVariable.get()+ "You clicked the button !")
self.entry.focus_set()
self.entry.selection_range(0, Tkinter.END)
def ConvertToCAD(self):
money = entry(self)
money = money * 1.05
self.labelVariable.set("The converted currency in CAD is " + money)
self.entry.focus_set()
self.entry.selection_range(0, Tkinter.END)
def OnPressEnter(self,event):
self.labelVariable.set(self.entryVariable.get()+ "You pressed enter !")
self.entry.focus_set()
self.entry.selection_range(0, Tkinter.END)
if __name__ == "__main__":
app = converter(None)
app.title('Currency Converter')
app.mainloop()
I get the error "NameError: global name 'entry' is not defined".. I'm trying to use the text inputted in the textbox as an integer variable usable to convert currency between CAD and USD.