Tkinter class not able to be called

I have been using python for about a year now in my current job and currently trying to learn about classes. For some reason I am am not able to call the class Game. When I run the code below I get a small box that shows up without any color or sizing and from what I can tell I am unable to print certain variables such as game.width. Any idea what I am missing on this or doing wrong?

import tkinter as tk #display graphic user interface

class Game(tk.Frame):
    def __init_(self, master):
        #create window
        self.width = 1000;
        self.height = 400;
        #create canvas
        self.canvas = tk.Canvas(self, bg = 'blue',
                                            width = self.width,
                                            height = self.height)
        self.items = {}
    def init_game(self):
    def start_game(self):
        self.canvas.unbind('<space>') #press space bar

if __name__ == '__main__':
    root.title('Brick Breaker')
    game = Game(root) #calling game function
    game.mainloop() #loops around game

It looks, to me, as if you have a malformed dunder: def __init_(self, master):

Try: def __init__(self, master):

1 Like

I feel like an idiot, thanks I that worked!!!

1 Like

Not at all: it’s called ‘code blindness’. It happens to me, if I’ve been coding for hrs at a time :slight_smile:

You’ll feel this a lot as you write code. But that doesn’t mean you ARE one. :slight_smile: We all make mistakes, often very dumb ones, and the key to being a good programmer is finding them and fixing them. Imagine that you fat-fingered something and brought a website down for a while. Now imagine that the website in question was Facebook. What do you do? You fix it, you learn, and now you have more experience.

You’re a programmer. It’s not your job to be perfect. It’s your job to make mistakes, then fix those mistakes, and next time, make different mistakes.

1 Like