Ver Mensaje Individual
  #2 (permalink)  
Antiguo 29/03/2011, 14:04
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

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()