im getting this name error for my button. I cant figure out why. Im using tkinter and I think Ive imported all the ne
#this the sound shart
start_game = Button (text_box,command=start_game_pressed, fg='black',text = """
丂七闩尺七
""")
start_game.place(x=450, y=400)
def start_game_pressed (self):
print("sus")
#subprocess.call(["afplay", "soundscrate-not-done2.wav"])
#text and textbox configuration
text_box.pack(expand=True)
text_box.insert('end', titletext,start_game )
text_box.config(state = 'disabled')
text_box.config(bg='black')
text_box.config(fg='white')
text_box.place(x=150, y=125)
gui.mainloop()
this is the error message
File "/Users/odinschaefer/Desktop/torture my/main.py", line 43, in <module>
start_game = Button (text_box,command=start_game_pressed, fg='black',text = """
NameError: name 'start_game_pressed' is not defined
help pls.
CodePudding user response:
You need to define the function before you try to reference it.
def start_game_pressed (self):
print("sus")
start_game = Button (text_box,command=start_game_pressed, fg='black',text = """
丂七闩尺七
""")
CodePudding user response:
You need to write your function before referencing it in the button. Something like this:
# Notice that here, the function is
# defined before the button is.
def start_game_pressed(self):
print(“sus”)
start_game = Button(text_box,command=start_game_pressed,
fg='black',text = "丂七闩尺七")