我的按鈕出現此名稱錯誤。我想不通為什么。我使用 tkinter,我想我已經匯入了所有的 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()
這是錯誤資訊
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
請幫助。
uj5u.com熱心網友回復:
您需要先定義函式,然后再嘗試參考它。
def start_game_pressed (self):
print("sus")
start_game = Button (text_box,command=start_game_pressed, fg='black',text = """
丂七閂尺七
""")
uj5u.com熱心網友回復:
在按鈕中參考它之前,您需要撰寫您的函式。像這樣的東西:
# 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 = "丂七閂尺七")
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/345034.html
