Foros del Web » Programando para Internet » Python »

dibujo en wxpython y textctrl

Estas en el tema de dibujo en wxpython y textctrl en el foro de Python en Foros del Web. tengo este codigo: import wx class cuadrado(wx.Frame): def __init__(self, parent,id, title): wx.Frame.__init__(self, parent,id, title,size=(700,700)) self.Centre() self.Show(True) self.Bind(wx.EVT_PAINT,self.onpaint) self.Bind(wx.EVT_BUTTON,self.valor) self.texto=wx.TextCtrl(self,-1,value="",pos=(40,40)) self.mostrar=wx.StaticText(self,-1, label="elija un circulo por su ...
  #1 (permalink)  
Antiguo 28/03/2011, 17:07
 
Fecha de Ingreso: diciembre-2010
Mensajes: 162
Antigüedad: 13 años, 4 meses
Puntos: 1
Pregunta dibujo en wxpython y textctrl

tengo este codigo:



import wx

class cuadrado(wx.Frame):
def __init__(self, parent,id, title):
wx.Frame.__init__(self, parent,id, title,size=(700,700))
self.Centre()
self.Show(True)

self.Bind(wx.EVT_PAINT,self.onpaint)
self.Bind(wx.EVT_BUTTON,self.valor)

self.texto=wx.TextCtrl(self,-1,value="",pos=(40,40))
self.mostrar=wx.StaticText(self,-1, label="elija un circulo por su color",pos=(20,20))
self.texto2=wx.TextCtrl(self,-1,value="",pos=(180,40))
self.mostrar2=wx.StaticText(self,-1, label="coloque un numero",pos=(170,20))
self.boton=wx.Button(self,label="ENTRAR DATO",pos=(170,70))

def valor(self, event):
val=self.texto2.GetValue()



def onpaint(self,event):
dc=wx.PaintDC(self)
pen=wx.Pen("BLUE",3,wx.SOLID)
dc.SetPen(pen)
dc.DrawRectangle(100,100,200,200)
dc.DrawLine(200,100,200,300)
dc.DrawLine(100,200,300,200)
d=wx.PaintDC(self)
pen2=wx.Pen("BLUE",3,wx.SOLID)
d.SetPen(pen2)
d.DrawCircle(100,100,10)



app=wx.App()
cuadrado(None,-1,"hola")
app.MainLoop()

yo quiero que cuando entre un numero en el textcontrol me dibuje el circulo en la posicion indicada por el usuario hasta ahora llegue a la conclusion de que tengo que usar el metodo getvalue y asignarle una variable en este caso val. pero si pongo asi:
d.DrawCircle(val,100,10) no me dibuja el circulo, lo demas si lo dibuja, que es lo que me falta???????
  #2 (permalink)  
Antiguo 29/03/2011, 14:04
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: dibujo en wxpython y textctrl

Espero que esto mas o menos te ayude.
Código Python:
Ver original
  1. import wx
  2.  
  3. class MyFrame(wx.Frame):
  4.     def __init__(self, parent,id, title):
  5.         wx.Frame.__init__(self, parent,id, title,size=(700,700))
  6.         self.Panel = Panel(self)
  7.         self.Show()
  8.  
  9. class DrawPanel(wx.Panel):
  10.     def __init__(self, *args, **kwargs):
  11.         wx.Panel.__init__(self, *args, **kwargs)
  12.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  13.         self.x = None
  14.         self.y = None
  15.         self.r = None
  16.    
  17.     def OnPaint(self, event):
  18.         dc = wx.PaintDC(self)
  19.         dc.SetPen(wx.Pen("BLACK", 4))
  20.         if(self.x is not None and self.y is not None and self.r is not None):
  21.             dc.DrawCircle(self.x, self.y, self.r)
  22.        
  23.  
  24. class Panel(wx.Panel):
  25.     def __init__(self, *args, **kwargs):
  26.         wx.Panel.__init__(self, *args, **kwargs)
  27.         box = wx.BoxSizer(wx.VERTICAL)
  28.        
  29.         box1 = wx.BoxSizer(wx.HORIZONTAL)
  30.         self.txt1 = wx.TextCtrl(self)
  31.         self.lbl1 = wx.StaticText(self, label='x:  ')
  32.         box1.Add(self.lbl1)
  33.         box1.Add(self.txt1)
  34.        
  35.        
  36.         box2 = wx.BoxSizer(wx.HORIZONTAL)
  37.         self.txt2 = wx.TextCtrl(self)
  38.         self.lbl2 = wx.StaticText(self, label='y:  ')
  39.         box2.Add(self.lbl2)
  40.         box2.Add(self.txt2)
  41.        
  42.         box3 = wx.BoxSizer(wx.HORIZONTAL)
  43.         self.txt3 = wx.TextCtrl(self)
  44.         self.lbl3 = wx.StaticText(self, label='radio:  ')
  45.         box3.Add(self.lbl3)
  46.         box3.Add(self.txt3)
  47.        
  48.         box.Add(box1)
  49.         box.Add(box2)
  50.         box.Add(box3)
  51.         self.bttn = wx.Button(self, label='Dibujar')
  52.         box.Add(self.bttn)
  53.         self.dc = DrawPanel(self)
  54.         box.Add(self.dc, 1, wx.EXPAND)
  55.        
  56.         self.SetAutoLayout(True)
  57.         self.SetSizer(box)
  58.         self.Layout()
  59.        
  60.         self.bttn.Bind(wx.EVT_BUTTON, self.OnClick)
  61.        
  62.     def OnClick(self, event):
  63.         try:
  64.             x = int(self.txt1.GetValue())
  65.             y = int(self.txt2.GetValue())
  66.             r = int(self.txt3.GetValue())
  67.         except ValueError:
  68.             print "x, y o radio no son numeros"
  69.             return
  70.         self.dc.x = x
  71.         self.dc.y = y
  72.         self.dc.r = r
  73.         self.dc.Update()
  74.         self.dc.Refresh()
  75.            
  76.        
  77.        
  78.  
  79. app = wx.App(0)
  80. f = MyFrame(None,-1,"hola")
  81. app.MainLoop()
  #3 (permalink)  
Antiguo 29/03/2011, 14:10
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: dibujo en wxpython y textctrl

Código Python:
Ver original
  1. import wx
  2.  
  3. class MyFrame(wx.Frame):
  4.     def __init__(self, parent,id, title):
  5.         wx.Frame.__init__(self, parent,id, title,size=(700,700))
  6.         self.Panel = Panel(self)
  7.         self.Show()        
  8.        
  9.  
  10. class Panel(wx.Panel):
  11.     def __init__(self, *args, **kwargs):
  12.         wx.Panel.__init__(self, *args, **kwargs)
  13.        
  14.         self.x = None
  15.         self.y = None
  16.         self.r = None
  17.        
  18.         box = wx.BoxSizer(wx.VERTICAL)
  19.        
  20.         box1 = wx.BoxSizer(wx.HORIZONTAL)
  21.         self.txt1 = wx.TextCtrl(self)
  22.         self.lbl1 = wx.StaticText(self, label='x:  ')
  23.         box1.Add(self.lbl1)
  24.         box1.Add(self.txt1)
  25.        
  26.        
  27.         box2 = wx.BoxSizer(wx.HORIZONTAL)
  28.         self.txt2 = wx.TextCtrl(self)
  29.         self.lbl2 = wx.StaticText(self, label='y:  ')
  30.         box2.Add(self.lbl2)
  31.         box2.Add(self.txt2)
  32.        
  33.         box3 = wx.BoxSizer(wx.HORIZONTAL)
  34.         self.txt3 = wx.TextCtrl(self)
  35.         self.lbl3 = wx.StaticText(self, label='radio:  ')
  36.         box3.Add(self.lbl3)
  37.         box3.Add(self.txt3)
  38.        
  39.         box.Add(box1)
  40.         box.Add(box2)
  41.         box.Add(box3)
  42.         self.bttn = wx.Button(self, label='Dibujar')
  43.         box.Add(self.bttn)
  44.        
  45.         self.SetAutoLayout(True)
  46.         self.SetSizer(box)
  47.         self.Layout()
  48.        
  49.         self.bttn.Bind(wx.EVT_BUTTON, self.OnClick)
  50.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  51.    
  52.     def OnPaint(self, event):
  53.         dc = wx.PaintDC(self)
  54.         dc.SetPen(wx.Pen("BLACK", 4))
  55.         if(self.x is not None and self.y is not None and self.r is not None):
  56.             dc.DrawCircle(self.x, self.y, self.r)
  57.        
  58.     def OnClick(self, event):
  59.         try:
  60.             x = int(self.txt1.GetValue())
  61.             y = int(self.txt2.GetValue())
  62.             r = int(self.txt3.GetValue())
  63.         except ValueError:
  64.             print "x, y o radio no son numeros"
  65.             return
  66.         self.x = x
  67.         self.y = y
  68.         self.r = r
  69.         self.Update()
  70.         self.Refresh()
  71.            
  72.        
  73.        
  74.  
  75. app = wx.App(0)
  76. f = MyFrame(None,-1,"hola")
  77. app.MainLoop()
Mismo código pero con un solo panel.
  #4 (permalink)  
Antiguo 04/04/2011, 16:34
 
Fecha de Ingreso: diciembre-2010
Mensajes: 162
Antigüedad: 13 años, 4 meses
Puntos: 1
Respuesta: dibujo en wxpython y textctrl

gracias por la respuesta me fue de mucha utilidad.sos un genio

Etiquetas: dibujo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:04.