How to close a window with the .destroy() function?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Marcozeus
    New Member
    • Nov 2014
    • 7

    How to close a window with the .destroy() function?

    Hi, my friend and I are doing a project and we have a problem with our code.

    There is the code:

    Code:
    from time import *
    from math import *
    from re import *
    from tkinter import *
    
    def getWord():
        rootMot = Tk()
        motTexte = Entry(rootMot)
        motTexte.pack()
        motTexte.delete(0, END)
        motTexte.insert(0, "Enter your word here")
        boutonMot = Button(rootMot, text="Submit", width=10, command=rootMot.destroy())
        boutonMot.pack()
        
    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()
    We want to close the "rootMot" window by pressing the button "boutonMot" but we don't know how. Can you please help us?

    Thank you

    PS: We are french so sorry if you don't understand some variables :)
    Last edited by Rabbit; Nov 8 '14, 02:21 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    It should be a Toplevel and no parens (a reference)
    Code:
    rootMot = Toplevel(root)
    ...
    boutonMot = Button(rootMot, text="Submit", width=10, command=rootMot.destroy)

    Comment

    • Marcozeus
      New Member
      • Nov 2014
      • 7

      #3
      Thank you very much, it worked ! :D

      Comment

      Working...