[New-bugs-announce] [issue17803] Calling Tkinter.Tk() with a baseName keyword argument throws UnboundLocalError

Yasuhiro Fujii report at bugs.python.org
Sat Apr 20 13:57:47 CEST 2013


New submission from Yasuhiro Fujii:

Calling Tkinter.Tk() with baseName keyword argument throws UnboundLocalError on Python 2.7.4.

A process to reproduce the bug:
>>> import Tkinter
>>> Tkinter.Tk(baseName="test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1748, in __init__
    if not sys.flags.ignore_environment:
UnboundLocalError: local variable 'sys' referenced before assignment

A patch to fix the bug:
--- Lib/lib-tk/Tkinter.py.orig
+++ Lib/lib-tk/Tkinter.py
@@ -1736,7 +1736,7 @@
         # ensure that self.tk is always _something_.
         self.tk = None
         if baseName is None:
-            import sys, os
+            import os
             baseName = os.path.basename(sys.argv[0])
             baseName, ext = os.path.splitext(baseName)
             if ext not in ('.py', '.pyc', '.pyo'):

----------
components: Tkinter
messages: 187418
nosy: y-fujii
priority: normal
severity: normal
status: open
title: Calling Tkinter.Tk() with a baseName keyword argument throws UnboundLocalError
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17803>
_______________________________________


More information about the New-bugs-announce mailing list