1

So I'm learning TkInter for school and I have to code my class schedule with different options. It was going fine but I've run into the problem where instead of replacing the text, it just writes over it.

Whenever I press the button is shows the text but if I were to press another button it displays the text over the displayed text instead of replacing it. I'm doing all the text in Label because its what worked.. tried text and all that but was causing me some other issues that Label fixed. But again, I'm new to this so if there's any fix for Label I'll welcome it but if the fix is to replace every Label with text then I'd just like to know how specifically. Thanks!

Here is my code:

from tkinter import *

class Asignatura:
  def __init__(self, dia, salon, h_comienzo, h_fin, curso, libre):
    self.dia = dia
    self.salon = salon
    self.h_comienzo = h_comienzo
    self.h_fin = h_fin
    self.curso = curso
    self.libre = libre

  def minutos(self, curso):
    minutes = self.h_fin[curso] % 100
    self.hora = (((self.h_fin[curso] - self.h_comienzo[curso]) // 100)*60) + minutes
    return(self.hora)


#en dos en dos
lu_mie = Asignatura("LW", "319", ["1800", "2000"], ["1955", "2155"], ["COMP 2501", "COMP 2400"],  "700 - 1800 : LIBRE")
mar_jue = Asignatura("MJ", "", "", "", ["CLASE ONLINE GEPE 4040", "CLASE ONLINE MATH 2251"],  "700 - 2200 : LIBRE")
vie_sab_dom = Asignatura("VSD", "", "", "", "", "700 - 2200 : LIBRE")




class TheGUI:
    def __init__(self, master):
        self.master = master
        master.title("-- PROGRAMA DE CLASES --")
        master.geometry('550x250')

        blankspace=StringVar()
        blankspace.set("")

        def ProgComp():
            self.label = Label(master, text=lu_mie.dia + " : " + lu_mie.libre).grid(row=2,column=3, sticky=E)
            self.label = Label(master, text=lu_mie.h_comienzo[0]+ " - "+ lu_mie.h_fin[0]+ ": "+ lu_mie.curso[0]+ " SALON: "+ lu_mie.salon).grid(row=3,column=3, sticky=E)
            self.label= Label(master, text= lu_mie.h_comienzo[1]+ " - "+ lu_mie.h_fin[1]+ ": "+ lu_mie.curso[1]+ " SALON: "+ lu_mie.salon).grid(row=4,column=3, sticky=E)
            self.label= Label(master, text= mar_jue.dia+ ": "+ mar_jue.libre+ "\n     "+ mar_jue.curso[0]+ "\n     "+ mar_jue.curso[1]).grid(row=5,column=3, sticky=E)
            self.label= Label(master, text=vie_sab_dom.dia+ ": "+ vie_sab_dom.libre).grid(row=6,column=3, sticky=E)

        def UnDia():
            #lunes y miercoles
            def luMieButton():
                self.label = Label(master, text=lu_mie.dia + " : " + lu_mie.libre).grid(row=1,column=4, sticky=W)
                self.label = Label(master, text=lu_mie.dia + " : " + lu_mie.libre).grid(row=2,column=4, sticky=W)
                self.label = Label(master, text=lu_mie.h_comienzo[0]+ " - "+ lu_mie.h_fin[0]+ ": "+ lu_mie.curso[0]+ " SALON: "+ lu_mie.salon).grid(row=3,column=4, sticky=W)
                self.label= Label(master, text= lu_mie.h_comienzo[1]+ " - "+ lu_mie.h_fin[1]+ ": "+ lu_mie.curso[1]+ " SALON: "+ lu_mie.salon).grid(row=4,column=4,sticky=W)

            #martes y jueves
            def marJueButton():
                self.label= Label(master, text= mar_jue.dia+ ": "+ mar_jue.libre+ "\n     "+ mar_jue.curso[0]+ "\n     "+ mar_jue.curso[1]).grid(row=1,column=4, sticky=W)
            #fin de semana
            def vieSabDomButton():
                self.label= Label(master, text= vie_sab_dom.dia+ ": "+ vie_sab_dom.libre).grid(row=1,column=4,sticky=W)
            #butones

            self.lunesDia = Button(master, text="LUNES", command=luMieButton).grid(row=1,column=100,sticky=E)
            self.martesDia = Button(master, text="MARTES", command=marJueButton).grid(row=2, column=100, sticky=E)
            self.miercolesDia = Button(master, text="MIERCOLES", command=luMieButton).grid(row=3,column=100,sticky=E)
            self.juevesDia = Button(master, text="JUEVES", command=marJueButton).grid(row=4, column=100, sticky=E)
            self.viernesDia = Button(master, text="VIERNES", command=vieSabDomButton).grid(row=5, column=100, sticky=E)
            self.sabadoDia = Button(master, text="SABADO", command=vieSabDomButton).grid(row=6, column=100, sticky=E)
            self.domingoDia = Button(master, text="DOMINGO", command=vieSabDomButton).grid(row=7, column=100, sticky=E)

        def Disponibilidad():
            pass






        self.progCompleto = Button(master, text="Programa Completo", command=ProgComp).grid(row=1, column=0, sticky=W)
        self.diaEspecifico = Button(master, text="Programa de un dia", command=UnDia).grid(row=2, column=0, sticky=W)
        self.horaDisponible = Button(master, text="Verificar Disponibilidad", command=Disponibilidad).grid(row=3, column=0, sticky=W)
        self.exit = Button(master, text="Close", command=master.destroy).grid(row=4, column=0, sticky=W)

root = Tk()
my_gui = TheGUI(root)
root.mainloop()
Ashlie
  • 11
  • 1
  • First you have to understand [Event-driven programming](https://stackoverflow.com/a/9343402/7414759) – stovfl Nov 01 '19 at 20:46

0 Answers0