Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103419

Re: exit from Tkinter mainloop Python 2.7

From Christian Gollwitzer <auriocus@gmx.de>
Newsgroups comp.lang.python
Subject Re: exit from Tkinter mainloop Python 2.7
Date 2016-02-23 23:29 +0100
Organization A noiseless patient Spider
Message-ID <naimao$327$1@dont-email.me> (permalink)
References <56e451a3-01f7-4883-b4db-c3a6a10729a9@googlegroups.com>

Show all headers | View raw


Am 23.02.16 um 22:39 schrieb kevind0718@gmail.com:
> from Tkinter import *
>
> def butContinue():
>      root1.destroy()
> [...]
> entryName = Entry(root1).grid(row=1, column=1, pady=5)
> [...]
> butGo  =  Button(root1, text="   Continue "  , command=butContinue ).grid(row=3, column=1, sticky=W, pady=10)
>
> root1.mainloop()
>
> print entryName.get("1.0", "end-1c" )

> When I click on butGo I get the error below.
> So is this some sort of scope error?
> why does entryName not exist for me to grab it's value?

You call destroy() on the root window of Tk. If you destroy a window, 
that will destroy all of it's children. Therefore by deleting the root 
window, also the entryName widget was deleted. You need to export the 
values before you close the window, i.e. in the butContinue() function.

There is another pitfall with Tk: if you delete the main window, you can 
get problems if you try to recreate it. If you want to show several 
pages in sequence or the like, you should withdraw the main window

	root1.withdraw()

and popup a fresh toplevel by

	t=Toplevel()
and do everything in t. Once you are finished, destroying t will keep 
your application alive (because the real root window is just hidden)

Another comment:

 > root1.geometry("500x250")

Do not do this. The grid and pack geometry managers compute the needed 
space automatically. A fixed size in pixels can easily break, when you 
go to another computer with a different font size, screen resolution, or 
a different OS. If you are not satisfied with the whitespace, use the 
padding options of grid or pack.

	Christian

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

exit from Tkinter mainloop  Python 2.7 kevind0718@gmail.com - 2016-02-23 13:39 -0800
  Re: exit from Tkinter mainloop Python 2.7 Christian Gollwitzer <auriocus@gmx.de> - 2016-02-23 23:29 +0100
    Re: exit from Tkinter mainloop Python 2.7 Peter Otten <__peter__@web.de> - 2016-02-23 23:45 +0100
  Re: exit from Tkinter mainloop Python 2.7 Christian Gollwitzer <auriocus@gmx.de> - 2016-02-23 23:33 +0100
    Re: exit from Tkinter mainloop Python 2.7 kevind0718@gmail.com - 2016-03-04 13:50 -0800
      Re: exit from Tkinter mainloop Python 2.7 Peter Otten <__peter__@web.de> - 2016-03-04 23:28 +0100
      Re: exit from Tkinter mainloop Python 2.7 Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-09 11:17 -0800
  Re: exit from Tkinter mainloop  Python 2.7 Dave Farrance <df@see.replyto.invalid> - 2016-02-24 09:34 +0000

csiph-web