By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

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

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

There is the code:

Expand|Select|Wrap|Line Numbers
  1. from time import *
  2. from math import *
  3. from re import *
  4. from tkinter import *
  5.  
  6. def getWord():
  7.     rootMot = Tk()
  8.     motTexte = Entry(rootMot)
  9.     motTexte.pack()
  10.     motTexte.delete(0, END)
  11.     motTexte.insert(0, "Enter your word here")
  12.     boutonMot = Button(rootMot, text="Submit", width=10, command=rootMot.destroy())
  13.     boutonMot.pack()
  14.  
  15. def exemple():
  16.     print("Word")
  17.  
  18.  
  19.  
  20.  
  21. root = Tk()
  22. menu = Menu(root)
  23. root.config(menu=menu)
  24.  
  25.  
  26. gameOptions = Menu(menu)
  27. menu.add_cascade(label="Game", menu=gameOptions)
  28. gameOptions.add_command(label="New Game", command=getWord)
  29. gameOptions.add_command(label="Options...", command=getWord)
  30. gameOptions.add_separator()
  31. gameOptions.add_command(label="Exit", command=getWord)
  32.  
  33.  
  34. helpOptions = Menu(menu)
  35. menu.add_cascade(label="Help", menu=helpOptions)
  36. helpOptions.add_command(label="How to play...", command=getWord)
  37. helpOptions.add_command(label="About...", command=getWord)
  38. mainloop()
  39.  
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 :)
Nov 8 '14 #1

✓ answered by dwblas

It should be a Toplevel and no parens (a reference)
Expand|Select|Wrap|Line Numbers
  1. rootMot = Toplevel(root)
  2. ...
  3. boutonMot = Button(rootMot, text="Submit", width=10, command=rootMot.destroy)

Share this Question
Share on Google+
2 Replies


Expert 100+
P: 621
It should be a Toplevel and no parens (a reference)
Expand|Select|Wrap|Line Numbers
  1. rootMot = Toplevel(root)
  2. ...
  3. boutonMot = Button(rootMot, text="Submit", width=10, command=rootMot.destroy)
Nov 8 '14 #2

P: 7
Thank you very much, it worked ! :D
Nov 8 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.