我在Rosetta Code - programming chrestomathy網站嘗試了一個python代碼示例,其中儘可能多的不同編程語言提供了對同一任務的解決方案。對於這個任務,目標是從圖形用戶界面輸入一個字符串和整數75000。代碼如下所示:最小tkSimpleDialog示例中的錯誤
import tkSimpleDialog
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
string = tkSimpleDialog.askstring("String", "Enter a String")
然而,當我嘗試運行的代碼,我得到以下錯誤:
Traceback (most recent call last):
File "C:\Users\vix\Documents\.cache\GUIexample.py", line 3, in <module>
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
File "C:\Python27\lib\lib-tk\tkSimpleDialog.py", line 262, in askinteger
d = _QueryInteger(title, prompt, **kw)
File "C:\Python27\lib\lib-tk\tkSimpleDialog.py", line 189, in __init__
Dialog.__init__(self, parent, title)
File "C:\Python27\lib\lib-tk\tkSimpleDialog.py", line 53, in __init__
if parent.winfo_viewable():
AttributeError: 'NoneType' object has no attribute 'winfo_viewable'
可能在哪裏這個問題呢?
感謝
發佈完整的追溯,而不僅僅是錯誤。我們需要查看錯誤代碼。 – agf 2012-04-18 08:02:53
@agf我編輯了問題以包含回溯。 – engineervix 2012-04-18 08:16:24
我在Windows 7 Ultimate 32位上使用Python 2.7。 'root = Tkinter.tk()'不起作用,它給出'NameError:name''Tkinter'沒有被定義' – engineervix 2012-04-18 08:28:37