user3920598
user3920598

Reputation: 3

Not able to make a table using tkinter (Python)

I am a complete newbee and trying to learn some python. Was trying to create a Table using the tkinter module but this is what I am running into: (I am trying to see if the Table class can successfully instantiate a visual table object with the supplied/default parameters)

The Code:

from Tkinter import *

class Table :
## contructor with the attributes
        def__init__(self,window,color='black',net_color='green',width=600,height=400,vertical_net=False,horizontal_net=False):
        self.width=width
        self.height=height
        self.color=color

my_table = Table(window)

And this is what I am getting:

Traceback (most recent call last):
  File "table.py", line 13, in <module>
    my_table = Table(window)
NameError: name 'window' is not defined

Greatly appreciate any help that comes my way.

Upvotes: 0

Views: 112

Answers (1)

laurencevs
laurencevs

Reputation: 923

The problem here is that window hasn't been defined and is never opened. You can fix this by doing this:

1) Add this line before the my_table = Table(window) line:

window = Tk() #create the window

2) Add this line after the my_table = Table(window) line:

window.mainloop() #open the window

Also, there is a space missing before the __init__()

Upvotes: 1

Related Questions