I want to delete the window "rootMot" by running the function "draw" when the button "boutonMot" is pressed. But this error keep showing up:
" File "C:\Users\Admin \Desktop\Codes Python\Bonhomme pendu.py", line 18, in draw
rootMot.destroy ()
NameError: global name 'rootMot' is not defined "
Here the code:
Thank you
PS: I'm french so sorry if you don't understand some variables :)
" File "C:\Users\Admin \Desktop\Codes Python\Bonhomme pendu.py", line 18, in draw
rootMot.destroy ()
NameError: global name 'rootMot' is not defined "
Here the code:
Code:
from time import *
from math import *
from re import *
from tkinter import *
def getWord():
rootMot = Toplevel(root)
motTexte = Entry(rootMot)
motTexte.pack()
motTexte.delete(0, END)
motTexte.insert(0, "Enter your word here")
boutonMot = Button(rootMot, text="Submit", width=10, command=draw)
boutonMot.pack()
def draw():
rootMot.destroy()
drawing = Tk()
gameDraw = Canvas(drawing, width=200, height=100)
gameDraw.pack()
gameDraw.create_line(0, 0, 200, 100)
gameDraw.create_line(0, 100, 200, 0, fill="red", dash=(4, 4))
gameDraw.create_rectangle(50, 25, 150, 75, fill="blue")
mainloop()
def exemple():
print("Word")
#######################################################################
root = Tk()
menu = Menu(root)
root.config(menu=menu)
gameOptions = Menu(menu)
menu.add_cascade(label="Game", menu=gameOptions)
gameOptions.add_command(label="New Game", command=getWord)
gameOptions.add_command(label="Options...", command=getWord)
gameOptions.add_separator()
gameOptions.add_command(label="Exit", command=getWord)
helpOptions = Menu(menu)
menu.add_cascade(label="Help", menu=helpOptions)
helpOptions.add_command(label="How to play...", command=getWord)
helpOptions.add_command(label="About...", command=getWord)
mainloop()
PS: I'm french so sorry if you don't understand some variables :)
Comment