From dudi at kolcore.com Tue Jun 21 05:34:52 2016 From: dudi at kolcore.com (Dudi Goldenberg) Date: Tue, 21 Jun 2016 09:34:52 +0000 Subject: [Tkinter-discuss] Tkinter canvas Message-ID: 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? TIA & Regards, Dudi -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Wed Jun 22 06:43:35 2016 From: klappnase at web.de (Michael Lange) Date: Wed, 22 Jun 2016 12:43:35 +0200 Subject: [Tkinter-discuss] Tkinter canvas In-Reply-To: References: Message-ID: <20160622124335.ee50c883eb581493aa0aded1@web.de> Hi, On Tue, 21 Jun 2016 09:34:52 +0000 Dudi Goldenberg 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 otherwise? 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 program. 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: http://effbot.org/tkinterbook/tkinter-index.htm There is also an excellent Tkinter reference available at http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html Finally there is also useful info to be found at the wiki: https://tkinter.unpythonic.net/wiki/ Of course you're always welcome here for further questions, too :) Good luck and best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. "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 5906.4