473,320 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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:

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)

2 2479
dwblas
626 Expert 512MB
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
Thank you very much, it worked ! :D
Nov 8 '14 #3

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

Similar topics

2
by: William Gill | last post by:
I am trying to make a simple data editor in Tkinter where each data element has a corresponding Entry widget. I have tried to use the FocusIn/FocusOut events to set a 'hasChanged' flag (if a...
2
by: Simon Fletcher | last post by:
Hello there, I need a "Close Window" script ( onLoad.Close.Window() ), however i need the script so it don't come up with this annoying window: "This window is trying to close" window. Is...
1
by: Ivan Sutton | last post by:
Hi, I'm quite new to Java: I installed a script which opened a window in a predefined format. It works fine! I want to know if it is possible to close that screen with java. (however, the...
1
by: Mark Rigsbee | last post by:
I was wonder if anyone out there could shed some light on a problem I am having. I'm having trouble getting a javascript "window.close()" method to work when running over a shared SSL connection....
3
by: mcyi2mr3 | last post by:
Hi all I'm new to javascript and im trying to add a close button function to my certain pages of my site. I use this code: <a href='javascript:window.close();'>Close Window</a> to create a...
16
by: ruca | last post by:
Hi, I have a popup (child) window that it is called by a button in my main (parent) window. How can I set the child window for not closing before the parent window? What do I have to do? ...
14
by: Paul | last post by:
Hi I have 2 functions in java script, one opens a second window-this works, the other is supposed to close this second window, does not seem to be working. Just wondering if anyone had any ideas....
2
by: NADZ | last post by:
Hi I've created a flash website that snaps to full screen. The problem im having is, that ive got an flash button on the flash movie that suppose to close the internet window completely. The...
4
by: Ubi | last post by:
I have a popup and I would like to capture the close window event. How can I do that in javascript? Daniele
3
by: drzoo2 | last post by:
Completely noob question as I am not a programmer but really trying hard to learn Python (Object oriented programming in general). I am writing a program in python that calls a popup window with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.