Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: MRAB Newsgroups: comp.lang.python Subject: Re: Simple tkinter query about creating a tk,StringVar() failure Date: Sun, 07 Feb 2016 01:52:44 +0000 Lines: 30 Message-ID: Reply-To: MRAB Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de QxIo5GNdoQW7lhOkJ+yH/ANIUJEQi4XAvwenM4SVIL0Q== 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; 'value,': 0.03; 'win32': 0.03; 'yet.': 0.03; 'root': 0.04; 'subject:query': 0.07; 'works.': 0.07; '__init__': 0.09; 'name)': 0.09; '>in': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'script?': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'gui': 0.18; 'windows': 0.20; '"",': 0.22; 'tkinter': 0.22; 'trying': 0.22; 'bit': 0.23; 'seems': 0.23; 'dec': 0.23; 'tried': 0.24; 'import': 0.24; '(most': 0.24; 'header :In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'skip:f 40': 0.27; 'skip:( 20': 0.28; 'loop,': 0.29; 'normally': 0.30; 'received:84': 0.32; 'run': 0.33; 'subject:Simple': 0.33; 'file': 0.34; 'fail': 0.35; 'skip:> 10': 0.35; "isn't": 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'list.': 0.37; 'skip:v 20': 0.38; 'does': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'header:Message- Id:1': 0.61; 'email addr:gmail.com': 0.62; 'more': 0.63; 'within': 0.64; 'tutor': 0.66; 'header:Reply-To:1': 0.67; 'suited': 0.72; 'subject:,': 0.82; '3.5.1': 0.84; 'window,': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=Iat6Ijea c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=pGLkceISAAAA:8 a=gmYC9CwWpMR18MvOgk0A:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 In-Reply-To: User-Agent: eM_Client/6.0.24432.0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 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:102601 On 2016-02-07 00:38:14, paul.hermeneutic@gmail.com wrote: >I know this may be more suited to the tutor list. I tried to >subscribe, but no response yet. > >Why does this interactive instantiation fail when it seems to work >when run in a script? > >(py35-64) C:\src\pygui>python >Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 >64 bit (AMD64)] on win32 >Type "help", "copyright", "credits" or "license" for more information. >>>> import tkinter as tk >>>> name =3D tk.StringVar() >Traceback (most recent call last): > File "", line 1, in > File "C:\Program Files\Python35\lib\tkinter\__init__.py", line 329, >in __init__ > Variable.__init__(self, master, value, name) > File "C:\Program Files\Python35\lib\tkinter\__init__.py", line 233, >in __init__ > self._root =3D master._root() >AttributeError: 'NoneType' object has no attribute '_root' It's just down to the way that tkinter works. It's normally called within a GUI program which has windows and an event= =20 loop, and it's trying to get the root (top-level) window, but there=20 isn't one.