El caso es que estoy traspasando un programilla que hice a wxpython. El problema es que tengo hecho el code pero me da error en la linea 20 en negativa = ... y no se que es. Si me pudierais ayudar...
Aqui os dejo el code:
import wx
import math
class Herr(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent=None, title='Ecuaciones 2 grado')
self.btnCalcular = wx.Button(self, label='Calcular', pos=(20, 180), size=(60, 30))
self.a = wx.TextCtrl(self, pos=(20,45), size=(60,20))
self.b = wx.TextCtrl(self, pos=(20,70), size=(60,20))
self.c = wx.TextCtrl(self, pos=(20,95), size=(60,20))
self.d = wx.TextCtrl(self, pos=(20,120), size=(60,20))
self.e = wx.TextCtrl(self, pos=(20,145), size=(60,20))
self.Bind(wx.EVT_BTN, self.ecuacion, self.btnCalcular)
def ecuacion(self, event):
try:
a = self.a.GetValue()
b = self.b.GetValue()
c = self.c.GetValue()
positiva = self.d.SetValue((-b + math.sqrt(b*b - 4*a*c))/(2*a))
negativa = self.e.SetValue((-b - math.sqrt(b*b - 4*a*c))/(2*a))
except:
positiva = self.d.SetValue('Sin solucion')
negativa = self.e.SetValue('Sin solucion')
class App(wx.App):
def OnInit(self):
frame = Herr()
frame.Show()
self.SetTopWindow(frame)
return True
if __name__ == '__main__':
app = App()
app.MainLoop()
Que error te da EXACTAMENTE? :P Obviamente no es problema de la interfaz
Saludos
creo que ya lo arregle. Era problema en la funcion "ecuacion" que he puesto los SetValue como str porque los int no los coge bien creo
Asi me quedo:
def ecuacion(self, event):
try:
a = int(self.a.GetValue())
b = int(self.b.GetValue())
c = int(self.c.GetValue())
self.d.SetValue(str((-b + math.sqrt(b*b - 4*a*c))/(2*a)))
self.e.SetValue(str((-b - math.sqrt(b*b - 4*a*c))/(2*a)))
except:
self.d.SetValue('Sin solucion')
self.e.SetValue('Sin solucion')
Ya entendí, creo que el problema si era de la interfaz :xD , dije que no porque me pareció raro que no saliera en el "positivo" y si en "negativo". Supongo, y digo supongo porque no soy de crear GUIs para python que el Textctrl retorna un string, y es por eso que luego te lo reconoce como tal :P, así que seguramente tendrás que hacer lo mismo siempre.
Saludos
Gracias Novlucker por eso. Y ahora otra cosa xD
para poner un texto al lado de cada recuadro he hecho esto:
wx.Frame.__init__(self, parent=None, title='Ecuaciones 2 grado')
self.btnCalcular = wx.Button(self, label='Calcular', pos=(20, 180), size=(60, 30))
self.a = wx.TextCtrl(self, pos=(20,45), size=(60,20))
self.b = wx.TextCtrl(self, pos=(20,70), size=(60,20))
self.c = wx.TextCtrl(self, pos=(20,95), size=(60,20))
self.d = wx.TextCtrl(self, pos=(20,120), size=(60,20))
self.e = wx.TextCtrl(self, pos=(20,145), size=(60,20))
wx.StaticTex(self, label='Introduzca a', pos=(10,45))
wx.StaticTex(self, label='Introduzca b', pos=(10,70))
wx.StaticTex(self, label='Introduzca c', pos=(10,95))
wx.StaticTex(self, label='Resultado postivo', pos=(10,120))
wx.StaticTex(self, label='Resultado negativo', pos=(10,145))
self.Bind(wx.EVT_BUTTON, self.ecuacion, self.btnCalcular)
pero al ejecutarlo no sale el texto xD. Si me pudieras ayudar... :D
Y no se parte?
StaticText
Saludos
No te entendi :huh:
Tu estas poniendo wx.StaticTex, y debería de ser wx.StaticText, por eso pregunto si no se parte.
Saludos
Ya lo arregle. Gracias Novlucker :D