[Tkinter-discuss] Tkinter canvas

Michael Lange klappnase at web.de
Wed Jun 22 06:43:35 EDT 2016


On Tue, 21 Jun 2016 09:34:52 +0000
Dudi Goldenberg <dudi at kolcore.com> wrote:

> Hi,
> I have this:
> from Tkinter import *
> canvas = Canvas(width = 320, height = 320, bg = 'white')
> Now I have the canvas window, I can add images and add/manipulate text
> within the window.
> I can delete the objects with canvas.delete(obj_id), but after all
> objects are gone, I am still left with the initial window.
> Canvas.destroy(), canvas.quit() has no effect on it.
> I even tried to remove the Tkinter modules, but the window is still
> there.
> Is there a safe way to get rid of the canvas window?

I guess this is not all of the code you have tried, since without calling
something like canvas.pack() or canvas.grid() you won't be able to see
the canvas widget :)
Also I guess that you tried this from the "interactive" Python shell,
since canvas.quit() did not close the application window, which it should

One problem with your code snippet is, that it does not offer a handle to
the main Tk window, which is created silently in the background. Calling
canvas.destroy() only destroys the Canvas and its children (if any) of
course and leaves the main app window alone.

If you change your example a little into:

>>> from Tkinter import *
>>> root = Tk()
>>> canvas = Canvas(root, width = 320, height = 320, bg = 'white')
>>> canvas.pack()

you can call root.destroy() to close the application window (which is in
fact by default the same as clicking the "X" button in the window's upper
right corner does).

When you run your code example from a python file with something like
	python yourapp.py 
calling quit() on any widget should close the window and end the

In case you don't already know these:
Maybe you want to have a look at Frederik Lundh's "Introduction to
Tkinter" for more examples on how to get started:
There is also an excellent Tkinter reference available at
Finally there is also useful info to be found at the wiki:

Of course you're always welcome here for further questions, too :)

Good luck and best regards


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

	"The combination of a number of things to make existence
worthwhile." "Yes, the philosophy of 'none,' meaning 'all.'"
		-- Spock and Lincoln, "The Savage Curtain", stardate

More information about the Tkinter-discuss mailing list