Search code examples
pythonpython-3.xtkinterchesstkinter-canvas

Chessboard GUI 2D View


I would like to create a 2D chessboard representation for the GUI of my chess game with Tkinter. I programmed this code but it doesn't display the chessboard, it just displays the grey background. There is no indentation problem. What's the problem, and how can I fix it?

This is the error I get when I run the program:

Traceback (most recent call last):
  File "D:\Chess\GAME\gui.py", line 32, in <module>
    main()
  File "D:\Chess\GAME\gui.py", line 29, in main
    gui = GUI(root)
  File "D:\Chess\GAME\gui.py", line 14, in __init__
    self.draw_board()
AttributeError: 'GUI' object has no attribute 'draw_board'

Solution

  • Actually, there is an indentation problem. You've made draw_board a sub-function of __init__, rather than a class method. Pull it left to the same level as __init__ so it can be a property of your object GUI.