Path: csiph.com!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'below)': 0.05; 'initialize': 0.07; 'received:verizon.net': 0.07; 'subject:when': 0.07; 'terry': 0.07; 'bind': 0.09; 'prefix': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tkinter': 0.09; 'underscores': 0.09; 'def': 0.13; 'great.': 0.15; '"from': 0.16; '"import': 0.16; 'braces?': 0.16; 'reedy': 0.16; 'subject:() ': 0.16; 'subject:GUI': 0.16; 'subject:app': 0.16; 'subject:writing': 0.16; 'url:bugs': 0.17; 'wrote:': 0.18; 'alternate': 0.18; 'jan': 0.19; 'seems': 0.20; 'suggest': 0.20; 'downloaded': 0.21; 'header:In-Reply-To:1': 0.22; 'changed': 0.23; 'referring': 0.23; 'command': 0.24; 'windows': 0.26; 'module': 0.26; 'import': 0.27; '(see': 0.28; 'version,': 0.28; 'class': 0.29; 'example': 0.29; 'problem': 0.29; 'pm,': 0.29; 'url:library': 0.31; 'subject:?': 0.31; 'app': 0.31; 'skip:( 20': 0.31; 'minor': 0.32; 'ps:': 0.32; 'does': 0.32; 'there': 0.33; 'header:User-Agent:1': 0.33; 'header:X-Complaints-To:1': 0.34; 'doc': 0.34; 'root': 0.34; 'to:addr:python-list': 0.35; 'things': 0.35; 'window': 0.35; 'skip:" 20': 0.35; 'url:python': 0.35; 'received:org': 0.36; 'issue': 0.37; 'instead,': 0.37; 'but': 0.37; 'using': 0.37; 'subject:with': 0.37; 'skip:_ 10': 0.38; 'url:org': 0.39; 'that.': 0.39; 'johnson': 0.39; 'to:addr:python.org': 0.40; 'simple,': 0.64; 'here': 0.64; 'spaces': 0.73; '10:22': 0.84; 'subject:necessary': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Is it necessary to call Tk() when writing a GUI app with Tkinter? Date: Thu, 01 Mar 2012 00:24:06 -0500 References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1330579461 news.xs4all.nl 6881 [2001:888:2000:d::a6]:58649 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21069 On 2/29/2012 10:22 PM, Rick Johnson wrote: I do not know what book the OP is referring to, but the current doc example is http://docs.python.org/py3k/library/tkinter.html#a-simple-hello-world-program My current replacement (see below) can be downloaded from the tracker: http://bugs.python.org/issue14163 > If you want to keep things simple, i would: > > 1. Create the root window explicitly! It already does that. > 2. Bind the command of the button to root.destroy > (command=root.destroy) That works great. My current replacement example is uploaded to the issue http://bugs.python.org/issue14163 > PS: I would highly suggest against using the "from Tkinter import *". > Instead, use "import Tkinter as tk" and prefix all module contents > with "tk.". I have changed the example to do that. I also showed the alternate to initialize a widget. Here is the current version, tested on Windows 3.2.2. import tkinter as tk class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.pack() self.createWidgets() def createWidgets(self): self.hi_there = tk.Button(self) self.hi_there["text"] = "Hello_World\n(click_me)", self.hi_there["command"] = self.say_hi self.hi_there.pack({"side": "top"}) self.QUIT = tk.Button(self, text = "QUIT", fg = "red", command = root.destroy) self.QUIT.pack({"side": "bottom"}) def say_hi(self): print("hi there, everyone!") root = tk.Tk() app = Application(master=root) app.mainloop() There is a minor problem left. The hi_there Button text has underscores because if I use spaces instead, tk surrounds the text with {bra ces}. This seems bizarre. Is there any way to have Button text with spaces and no braces? -- Terry Jan Reedy