[Python-es] listas Python/PMW
Martha Lucía Gallego López
mgallegol en gmail.com
Vie Abr 4 18:38:20 CEST 2008
Hola a todos los listeros: Trabajo sobre la versión python 2.4 sobre
la plataforma windows xp.
El código q adjunto me permite introducir n datos; cada vez q inserto
un dato me pregunta desea ingresar otro dato(SI/NO); una vez cliqueado
NO... me gustaria presentar en ventana el resultado de todos los
valores q se introdujeron, he considerado hacerlo a través de
listas, podrían darme alguna luz por favor de como hacerlo.
Agradezco su ayuda.
cordial saludo,
Martha L.
------------ próxima parte ------------
# -*- coding: cp1252 -*-
from Tkinter import *
import Pmw
def calculo(name,index,mode):
global x1
x1= valor1.get()
if x1:
x1= float(x1)
else:
valor1.set(x1)
x1=0
def lectura(bcerrar):
dialogo.deactivate(bcerrar)
def continuar(res):
if res=='SI':
dialogoContinuar.deactivate(res)
dato1()
else:
dialogoContinuar.deactivate(res)
r.destroy()
ri=Toplevel()
c=0
for n in range(r.num):
Label(ri, textvariable=valor1).grid(row=c, column=0)
c=c+1
ri.mainloop()
def ok():
dialogoContinuar.activate(geometry = 'centerscreenalways')
def dato():
global r, dialogo, dialogoContinuar,valor1, mensajeContinuar, ldato, c2
r=Tk()
r.num=1
ldato=[]
valor1=DoubleVar()
valor1.set(float(0.0))
valor1.trace_variable("w", calculo)
for n in range(r.num):
Label(r, text='%d'%r.num, width=4).grid(row=0, column=0)
c2=Entry(r, textvariable=valor1, width=4).grid(row=1, column=0)
ldato.append(c2)
Button(r, text='Continua', command=ok).grid(row=2, column=0)
dialogo = Pmw.MessageDialog(r,
title = 'Aviso',
message_text= 'No ha ingresado datos',
iconpos = 'w',
icon_bitmap = 'error',
defaultbutton = 0,
command=lectura)
dialogo.iconname('Aviso')
dialogo.withdraw()
dialogoContinuar= Pmw.Dialog(r,
buttons = ('SI', 'NO'),
command=continuar)
dialogoContinuar.withdraw()
mensajeContinuar= Label(dialogoContinuar.interior(),
text='¿desea ingresar otro dato?',
background='black',
foreground='white',
pady=20)
mensajeContinuar.pack(expand = 1, fill = 'both', padx = 4, pady = 4)
r.mainloop()
def dato1():
r.num=r.num+1
for n in range(r.num):
Label(r, text='%d'%r.num, width=4).grid(row=0, column=0)
c2=Entry(r, textvariable=valor1, width=4).grid(row=1, column=0)
Button(r, text='Continua', command=ok).grid(row=2, column=0)
dialogo = Pmw.MessageDialog(r,
title = 'Aviso',
message_text= 'No ha ingresado datos',
iconpos = 'w',
icon_bitmap = 'error',
defaultbutton = 0,
command=lectura)
dialogo.iconname('Aviso')
dialogo.withdraw()
dialogoContinuar= Pmw.Dialog(r,
buttons = ('SI', 'NO'),
command=continuar)
dialogoContinuar.withdraw()
mensajeContinuar= Label(dialogoContinuar.interior(),
text='¿desea ingresar otro dato?',
background='black',
foreground='white',
pady=20)
mensajeContinuar.pack(expand = 1, fill = 'both', padx = 4, pady = 4)
d=dato()
Más información sobre la lista de distribución Python-es