Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: exit from Tkinter mainloop Python 2.7 Date: Fri, 04 Mar 2016 23:28:03 +0100 Organization: None Lines: 93 Message-ID: References: <56e451a3-01f7-4883-b4db-c3a6a10729a9@googlegroups.com> <539a3e8d-31eb-4199-9c05-03a89b2dab91@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de d4iYNRHmAsX793BG8ehUKQ/I9qNNV0ggNwQAWSqZy1kA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'default)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:2.7': 0.09; 'output': 0.13; 'skip:# 20': 0.13; 'def': 0.13; "skip:' 30": 0.15; 'entryname': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:Tkinter': 0.16; 'tk()': 0.16; 'variable.': 0.16; 'wrote:': 0.16; 'variable': 0.18; 'tkinter': 0.22; 'advance.': 0.23; 'this:': 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'error': 0.27; 'skip:# 10': 0.27; 'function': 0.28; 'values': 0.28; 'looks': 0.29; 'question:': 0.29; 'print': 0.30; 'code': 0.30; 'reported': 0.32; "skip:' 20": 0.34; 'text': 0.35; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'christian': 0.38; 'why': 0.39; 'subject:from': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'email addr:gmail.com': 0.62; 'matter.': 0.66; 'here': 0.66; 'attention': 0.76; 'others:': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd9a6f.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104058 kevind0718@gmail.com wrote: > > > Christian & Others: > > Thanks for your attention to this matter. > My code now look like this: > > from Tkinter import * > > > def butContinue(): > dbUser = entryName.get() Here you set the local variable dbUser (every name you rebind inside a function is local to that function by default) > pWord = entryPWord.get() > print dbUser and here you print it. > print pWord > root1.quit() > > > dbUser = "" Here you set the global variable dbUser > pWord = "" > root1 = Tk() > ##root1.geometry("500x250") > > > lblTop = Label(root1, text= ' Enter Values Below', font="Helvetica > 14").grid(row=0, column=0, columnspan=2 , pady=5) > ##lblTop.pack(side = TOP) > > lblDB = Label(root1, text= 'Weight').grid(row=1, column=0 ) > lblPWord = Label(root1, text= 'Height').grid(row=2,column=0) > entryName = Entry(root1) > entryName.grid(row=1, column=1, pady=5) > > entryPWord = Entry(root1) > entryPWord.grid(row=2, column=1, pady = 5) > > butGo = Button(root1, text=" Continue " , command=butContinue > ).grid(row=3, column=1, sticky=W, pady=10) > > > root1.mainloop() > > print "After the MainLoop" > print dbUser and here you print that global variable. > print pWord > > After I type in the text Weight and Height > No error are reported and output looks like this: > > Weight > Height > After the MainLoop > > > Question: > Why did this code not cause Weight and Height to print again. > > print "After the MainLoop" > print dbUser > print pWord > > Thanks in advance. If you want > def butContinue(): > dbUser = entryName.get() > pWord = entryPWord.get() to change the global dbUser and pWord you need to declare them as global explicitly: > def butContinue(): global dbUser, pWord > dbUser = entryName.get() > pWord = entryPWord.get()