2011-12-15 170 views
0

我有蟒蛇2.7.2-4(的Archlinux),並從Tkinter.StringVar()拋出一個異常

import Tkinter 
Tkinter.StringVar() 

結果

Traceback (most recent call last): 
    File "/tmp/foo.py", line 3, in <module> 
    foo = Tkinter.StringVar() 
    File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 251, in __init__ 
    Variable.__init__(self, master, value, name) 
    File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 182, in __init__ 
    self._tk = master.tk 
AttributeError: 'NoneType' object has no attribute 'tk' 
Exception AttributeError: "StringVar instance has no attribute '_tk'" in <bound method StringVar.__del__ of <Tkinter.StringVar instance at 0x1815710>> ignored 

回答

1

呼叫tk.Tk()tk.StringVar()前:

import Tkinter as tk 

root=tk.Tk()  
tk.StringVar()