steveone
March 5th, 2011, 03:05 AM
Hey guys. I'm new to python and I've been struggling with this problem for a while. I've search google and youtube but no luck so far. I've written this in IDLE 2.6.5. If someone could tell me why I'm getting the can't multiply sequence by non-int of type float error.
#GUIConverter.py
#This is the GUI version of the converter
import wx
import math
class converter(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Temperature Converter', size = (300, 200))
panel = wx.Panel(self)
self.status = wx.StaticText(panel, wx.ID_ANY, 'Enter The Temperature Below', pos=(10,5))
self.input = wx.TextCtrl(panel, -1, "30", size=(125, -1), pos=(15, 30), style=wx.TE_PROCESS_ENTER)
celsius = wx.Button(panel, label = "Celsius", pos = (10, 100), size = (75, 30) )
fehrenheit = wx.Button(panel, label = "Fehrenheit", pos = (130, 100), size = (95, 30) )
button = wx.Button(panel, label ="exit", pos = (75, 140), size = (60, 30))
self.Bind(wx.EVT_BUTTON, self.celsiusClick, celsius)
self.Bind(wx.EVT_BUTTON, self.fehrenheitClick, fehrenheit)
self.Bind(wx.EVT_BUTTON,self.closebutton, button)
self.Bind(wx.EVT_CLOSE, self.closewindow)
self.Show(True)
def celsiusClick(self, event):
#this gets the title of the button clicked
label = event.GetEventObject().GetLabel()
if label == "Celsius":
try:
c = self.input.GetValue()
c = (9.0/5.0) * c + 32
if not c.strip():
return
result = eval(c)
self.input.Insert(c, 0)
self.input.SetValue(str(result))
except Exception, e:
wx.LogError(str(e))
return
else:
self.equal.SetFocus()
def fehrenheitClick(self, event):
label = event.GetEventObject().GetLabel()
if label == "Fehrenheit":
try:
c = self.display.GetValue()
celsius = c - 32.0 / 9.0/5.0
if not celsius.strip():
return
result = eval(celsius)
self.display.SetValue(str(result))
except Exception, e:
wx.LogError(str(e))
return
def closebutton(self, event):
self.Close(True)
def closewindow(self, event):
self.Destroy()
if __name__=='__main__':
app = wx.PySimpleApp()
frame = converter(parent = None, id = -1)
#dlg = converter(None, -1)
try:
app.MainLoop()
finally:
del app
#GUIConverter.py
#This is the GUI version of the converter
import wx
import math
class converter(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Temperature Converter', size = (300, 200))
panel = wx.Panel(self)
self.status = wx.StaticText(panel, wx.ID_ANY, 'Enter The Temperature Below', pos=(10,5))
self.input = wx.TextCtrl(panel, -1, "30", size=(125, -1), pos=(15, 30), style=wx.TE_PROCESS_ENTER)
celsius = wx.Button(panel, label = "Celsius", pos = (10, 100), size = (75, 30) )
fehrenheit = wx.Button(panel, label = "Fehrenheit", pos = (130, 100), size = (95, 30) )
button = wx.Button(panel, label ="exit", pos = (75, 140), size = (60, 30))
self.Bind(wx.EVT_BUTTON, self.celsiusClick, celsius)
self.Bind(wx.EVT_BUTTON, self.fehrenheitClick, fehrenheit)
self.Bind(wx.EVT_BUTTON,self.closebutton, button)
self.Bind(wx.EVT_CLOSE, self.closewindow)
self.Show(True)
def celsiusClick(self, event):
#this gets the title of the button clicked
label = event.GetEventObject().GetLabel()
if label == "Celsius":
try:
c = self.input.GetValue()
c = (9.0/5.0) * c + 32
if not c.strip():
return
result = eval(c)
self.input.Insert(c, 0)
self.input.SetValue(str(result))
except Exception, e:
wx.LogError(str(e))
return
else:
self.equal.SetFocus()
def fehrenheitClick(self, event):
label = event.GetEventObject().GetLabel()
if label == "Fehrenheit":
try:
c = self.display.GetValue()
celsius = c - 32.0 / 9.0/5.0
if not celsius.strip():
return
result = eval(celsius)
self.display.SetValue(str(result))
except Exception, e:
wx.LogError(str(e))
return
def closebutton(self, event):
self.Close(True)
def closewindow(self, event):
self.Destroy()
if __name__=='__main__':
app = wx.PySimpleApp()
frame = converter(parent = None, id = -1)
#dlg = converter(None, -1)
try:
app.MainLoop()
finally:
del app