Consulta sobre Tkinter y Label(textvariable)

Eduardo eduardo.ulfe en gmail.com
Mar Oct 28 20:56:39 CET 2008


Hola a todos, estoy haciendo un pequeño gui en Tkinter y me surgio un
problema.
Según la documentación que tengo, un widget Label puede tener texto variable
asignanadole a la opción textvariable una variable de la clase StringVar(),
y luego esta variable puede modificarse usando variable.set('nuevo valor').
La cuestión es que esto no me funciona en mi código (aparecen los Label pero
sin texto dentro). Lo he probado en un codigo aparte y si funciona, así que
algo estoy haciendo mal pero no se que es.
Marco la zona donde tengo el problema:



from Tkinter import *
import os
import time
import Gnuplot



class Programa:

    def __init__(self, Padre):

        self.cont = Frame(Padre)
        self.padre = Padre
        self.cont.grid()

        self.etiq_dirbase = Label(self.cont, text = "Directorio Base: ")
        self.etiq_dirbase.grid(row=0, column=0)

        self.dirbase_txt = StringVar()
        self.ent_dirbase = Entry(self.cont, textvariable = self.dirbase_txt)
        self.ent_dirbase.grid(row=0, column=1)

        self.etiq_nombre = Label(self.cont, text = "Nombre del ensayo: ")
        self.etiq_nombre.grid(row=1, column=0)

        self.nombre_txt = StringVar()
        self.ent_nombre = Entry(self.cont, textvariable = self.nombre_txt)
        self.ent_nombre.grid(row=1, column=1)

        self.etiq_duracion = Label(self.cont, text = "Duracion (min): ")
        self.etiq_duracion.grid(row=2, column=0)

        self.duracion_txt = StringVar()
        self.ent_duracion = Entry(self.cont, textvariable =
self.duracion_txt)
        self.ent_duracion.grid(row=2, column=1)

        self.etiq_ts = Label(self.cont, text = "Tiempo de Muestreo (seg): ")
        self.etiq_ts.grid(row=3, column=0)

        self.ts_txt = StringVar()
        self.ent_ts = Entry(self.cont, textvariable = self.ts_txt)
        self.ent_ts.grid(row=3, column=1)

        self.ensayo_on = 0
        self.bot_iniciar = Button(self.cont, text="Iniciar", command =
self.Ensayo)
        self.bot_iniciar.grid(row=4, column=0, sticky=N+S+E+W)

        self.bot_salir = Button(self.cont, text="Salir", command =
self.Quit)
        self.bot_salir.grid(row=4, column=1, sticky=N+S+E+W)






    def Ensayo (self):


        if (self.ensayo_on ==
0):
############################ EMPIEZA LA ZONA PROBLEMATICA

            self.ensayo_on = 1
            self.ensayo_win = Tk()
            self.ensayo_win.title(self.nombre_txt.get())
            self.win1 = Frame(self.ensayo_win)
            #self.win1.grid()
            self.win1.pack()


            self.etiq_temp1 = Label(self.win1, text = "Temperatura 1: ")
            #self.etiq_temp1.grid(row=0, column=0)
            self.etiq_temp1.pack()

            self.temp1_txt = StringVar()
            self.show_temp1 = Label(self.win1, textvariable =
self.temp1_txt)
            #self.show_temp1.grid(row=0, column=1)
            self.show_temp1.pack()
            self.temp1_txt.set("----")

            self.etiq_temp2 = Label(self.win1, text = "Temperatura 2: ")
            #self.etiq_temp2.grid(row=1, column=0)
            self.etiq_temp2.pack()


            self.temp2_txt = StringVar()
            self.show_temp2 = Label(self.win1, textvariable =
self.temp2_txt)
            #self.show_temp2.grid(row=1, column=1)
            self.show_temp2.pack()
            self.temp2_txt.set('----')


######################### FIN DE LA ZONA PROBLEMATICA



Espero que alguien me pueda hechar una mano pq ya probe de todo, si no nol
os molestaría.

Muchas Gracias.





    def Quit(self):


        #self.ensayo_win.destroy()
        self.padre.destroy()

        return None




root = Tk()
prog = Programa(root)
root.title("Interfaz para Rheometros Beta 1")
root.mainloop()






-- 
No hay un mundo feliz,
pero igual lo iremos a buscar.
Si mi copa está vacía,
alguien la va a llenar.

Cúanta Cerveza ! - A77aque
_______________________________________________
Lista de correo Python-es 
http://listas.aditel.org/listinfo/python-es
FAQ: http://listas.aditel.org/faqpyes





Más información sobre la lista de distribución Python-es