How do I update label text with variables outside the primary class method?
22:07 05 May 2026

In the following window, I intend to have the labels on the right to be updated as the variables relating to these labels are modified

enter image description here

class MyFrame(ttk.Frame):
    
    ...

    Happiness = 21
    Hstat = "Happiness: [" + "|" * Happiness + "· " * (25 - Happiness) + "]"
    Fullness = 21
    Fstat = "Fullness:      [" + "|" * Fullness + "· " * (25 - Fullness) + "]"
    Energy = 21
    Estat = "Energy:        [" + "|" * Energy + "· " * (25 - Energy) + "]"

    Hlabel = tk.StringVar()
    Flabel = tk.StringVar()
    Elabel = tk.StringVar()

    def __init__(self, parent):
        ttk.Frame.__init__(self, parent, padding="10 10 10 10")
        self.pack()

        def animation():
            self.frame = (self.frame + 1) % len(self.PetFrames)
            self.canvas.itemconfig(self.image_id, image=self.PetFrames[self.frame])
            self.Hlabel.set(self.Hstat)
            self.Flabel.set(self.Fstat)
            self.Elabel.set(self.Estat)
            root.after(self.fps, animation)

    ...

    ttk.Button(self, text="Pet").grid(
            column=0, row=0)
        ttk.Button(self, text="Feed").grid(
            column=1, row=0)
        ttk.Button(self, text="Wash").grid(
            column=2, row=0)
        ttk.Button(self, text="Exit").grid(
            column=3, row=0)
        Hlabel = ttk.Label(self, textvariable=self.Hlabel).grid(
            column=4, row=1, pady=20)
        Flabel = ttk.Label(self, textvariable=self.Flabel).grid(
            column=4, row=2, pady=20)
        Elabel = ttk.Label(self, textvariable=self.Elabel).grid(
            column=4, row=3, pady=20)
        self.canvas = tk.Canvas(self, width=300, height=160)
        self.canvas.place(relx=0, rely=.2)
        self.img = self.PetFrames[self.frame]
        self.image_id = self.canvas.create_image(150, 90, image=self.img, tag="frame")
        animation()

I have not been able to get it working at all, even with various changes to the code, and while I would start from the beginning, I am unfortunately on borrowed time as this is a class project I'm working on

python tkinter label