This is a part of code from a tkinter game Random and tkinter module have been imported. The questions I have are -
1. The Struct class has only been initialized but not defined and simply passed yet it is used.
def run(rows, cols): # create the root and the canvas global canvas root = Tk() margin = 5 cellSize = 15 canvasWidth = 2*margin + cols*cellSize canvasHeight = 2*margin + rows*cellSize+100 canvas = Canvas(root, width=canvasWidth, height=canvasHeight) canvas.pack() # Store canvas in root and in canvas itself for callbacks root.canvas = canvas.canvas = canvas # Set up canvas data and call init class Struct: pass canvas.data = Struct() canvas.data.margin = margin canvas.data.cellSize = cellSize canvas.data.canvasWidth = canvasWidth canvas.data.canvasHeight = canvasHeight canvas.data.rows = rows canvas.data.cols = cols canvas.data.canvasWidth = canvasWidth canvas.data.canvasHeight = canvasHeight canvas.data.player1Score = 0 canvas.data.player2Score = 0 canvas.data.inGame = False init() # set up events root.bind("<Key>", keyPressed) timerFired() # and launch the app root.mainloop() # This call BLOCKS (so your program waits until you close the window!) run(40,40) 2. Also what is happening in this line of code:
root.canvas = canvas.canvas = canvas class Struct: pass canvas.data = Struct() - How are the canvas.data._______ being used since no class has been defined?