Home > front end >  Tkinter Label doesn't work as I thought it does
Tkinter Label doesn't work as I thought it does

Time:12-27

Beginner programmer here currently trying to learn Tkinter for a school assignment. I have a GUI class that stores the Tkinter labels etc, the labels are innitiated like this:

# GUI for Player 1
self.player_1_name_field = Label(
    self.root,
    text="Player 1",
    font=GUI_Settings.player_information_font,
    anchor=W,
    background=GUI_Settings.playerfield_active_color
)

I then create a Game() object that looks like this:

class Game():
def __init__(self):
    self.GUI = GUI()
    self.GUI.initializeBoard()
    self.GUI.root.mainloop()

When I run the code, the labels do get created and are where they are supposed to be, but are completely black. Once I move or resize the window it instantly becomes how I want it to be, it just behaves weird when at the start of the code

The interesting thing is that I also have a Canvas and a List that work perfectly fine, only the Labels are not cooperative

If you need further info, just ask for it! Thank you!

Edit 1: I have a function called drawWindow() that redraws the chessboard when I re-configure the window. In the init of the GUI class I set self.root.bind("<Configure>", self.drawWindow). If I remove that line of code, the Labels work but the Canvas doesn't anymore. I'm so confused. For anyone wanting to take a look at my tiny code: enter image description here

I found the information here (french forum).

  • Related