I am trying to create a code that establishes a menu on my gui using python. The issue is, it keeps calling the function the null function when I create the New option under file. It is only supposed to go off when I click on new, but it goes off when I run the program. I used the print function in null to let me know when it's being called
class Board:
def __init__(self, master):
self.master = master
self.setup()
def null(self):
print('o')
def setup(self):
board = tk.Canvas(self.master, width = 800, height = 800)
board.pack()
#Creates the Walls/Floor
board.create_line(0, 790,800, 790, width = 20) #Creates Bottom Line
board.create_line(10, 800,10, 100, width = 35) #Creates Left Wall
board.create_line(790, 800, 790, 100, width = 35) #Creates Right Wall
space = 20
for x in range(6): #Creates pillars
space += 108.5
board.create_line(space, 800, space, 150, width = 20)
board.pack()
def newgame(self):
self.menubar = tk.Menu(self.master)
self.filemenu = tk.Menu(self.master, tearoff = 0)
self.filemenu.add_command(label="New", command = self.null())
self.menubar.add_cascade(label="File", menu=self.filemenu)
self.filemenu.add_separator()
self.master.config(menu=self.menubar)