在最小的tkSimpleDialog示例中出错(Error in a minimal tkSimpleDialog example)

编程入门 行业动态 更新时间:2024-10-28 04:26:07
在最小的tkSimpleDialog示例中出错(Error in a minimal tkSimpleDialog example)

我在Rosetta Code上尝试了一个Python代码示例 - 一个编程chrestomathy站点,在这个站点中尽可能多地使用不同的编程语言提供同一任务的解决方案。 对于这个任务,目标是从图形用户界面输入一个字符串和整数75000。 代码如下所示:

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'

问题在哪里?

谢谢

I was trying out a python code example at Rosetta Code - a programming chrestomathy site, where solutions to the same task are presented in as many different programming languages as possible. For this task, the goal is to input a string and the integer 75000, from graphical user interface. The code is shown below:

import tkSimpleDialog number = tkSimpleDialog.askinteger("Integer", "Enter a Number") string = tkSimpleDialog.askstring("String", "Enter a String")

However, when I try to run the code, I get the following error:

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'

Where could the problem be?

Thanks

最满意答案

错误消息告诉你该对话需要一个父窗口。

使用Python 2.x,您可以创建根窗口:

import Tkinter root = Tkinter.Tk()

要隐藏根窗口(如果不需要),请使用:

root.withdraw()

有关更多信息,请参阅Python Tkinter文档 。

The error message is telling you that the dialog needs a parent window.

With Python 2.x, you create the root window with:

import Tkinter root = Tkinter.Tk()

To hide the root window if you don't want it, use:

root.withdraw()

See the Python Tkinter Docs for more info.

更多推荐

本文发布于:2023-07-07 15:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1065216.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:示例   最小   minimal   tkSimpleDialog   Error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!