Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/03/2011, 14:10
Avatar de razpeitia
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.