[pyar] Uso de variable Global

Juan Carlos Ojeda juancarlospaco en gmail.com
Jue Dic 2 20:52:11 ART 2010


2010/12/2 N Cis <n.cis_92 en hotmail.com>

>
> > Hola.
> >
> >
> > Estoy probando Tkinter y escribí este pequeño código el cual crea un
> > formulario con un textbox y un botón. Al ingresar un dato en el textbox
> > y presionar el botón, se imprime en la consola el valor.
> >
> > Funciona, pero tuve que hacer uso de una variable Global.
> >
> > Pregunta: ¿Es valida esta forma?, ¿Se puede hacer de otra forma, sin
> > ocuparla?.
> > Nota: Necesariamente la funcion muestra debe estar fuera de la clase App
>
> Usando google encontre esto, no se que tan correcto sea:
> Fuente: http://www.daniweb.com/forums/thread70644.html
>
>  ---CODE--------------------
>  from Tkinter import *
>
>  def muestra(valor):
>  print(valor.get())
>
>  class App:
>  def __init__(self,master):
>  valor = StringVar()
>  q1 = lambda: muestra(valor)
>  e = Entry(master,textvariable=valor).pack()
>  b = Button(master,text='Mostrar',command=q1).pack()
>
>
>  master = Tk()
>  app = App(master)
>  master.mainloop()
>  -----------------------------
>
>
>
>
> _______________________________________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>

+1 al Lambda derecho en el Command.

-- 
.
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20101202/d0c8de5c/attachment.html>


More information about the pyar mailing list