AttributeError: module 'PySimpleGUI' has no attribute 'Window'
AttributeError: module 'PySimpleGUI' has no attribute 'Window'
我正在尝试起床 运行 PySimpleGUI。我尝试了 运行 以下代码(来自 https://pysimplegui.readthedocs.io/en/latest/#the-quick-tour):
import PySimpleGUI as sg
event, values = sg.Window('Get filename example', [[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), sg.Cancel()] ]).Read()
这是在 Windows 7 盒子上,Python 3.7.1 和 PySimpleGUI 版本 4.18.0。
顺便说一句,我认为这两行应该在 python 命令行下工作。但是,即使我将它们保存为文件(没有其他 python 行,只有换行符和注释),我得到
(Traceback (most recent call last):
File "C:\Users\blorfmorlfle\bin\MoveStagedFiles.py", line 15, in <module>
event, values = sg.Window('Get filename example', [[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), sg.Cancel()] ]).Read()
AttributeError: module 'PySimpleGUI' has no attribute 'Window'
正在搜索类似错误的堆栈溢出,所有结果线程都不同。
FWIW,我已经卸载并重新安装了 PySimpleGUI。
FWIW2,以下工作正常。
sg.Popup('Hello From PySimpleGUI!', 'This is the shortest GUI program ever!')
有什么想法吗?我听说一些 python 版本由于 tkinter 问题而对 PySimpleGUI 有问题。有推荐的版本吗?
我用 python 3.6.8 和 PySimpleGUI 4.18.0 尝试过,使用你提供的相同的两行代码,但它对我也不起作用(内核死了)。
但是,运行 快速浏览 (https://pysimplegui.readthedocs.io/en/latest/#the-quick-tour) 中的另一个示例以更易读的方式简单地提供了代码,对我有用:
import PySimpleGUI as sg
sg.theme('Dark Blue 3') # please make your creations colorful
layout = [ [sg.Text('Filename')],
[sg.Input(), sg.FileBrowse()],
[sg.OK(), sg.Cancel()]]
window = sg.Window('Get filename example', layout)
event, values = window.Read()
window.close()
希望对您有所帮助
几年前我第一次安装 PySimpleGUI,只是为了玩玩它。听说它只有一个 python 文件,我就把它放到了我用来测试代码的文件夹中。
PySimpleGUI 的旧版本现在功能不全,因为它缺少 Window
、theme
等内容。我使用 pip 安装了最新版本。但是,我仍然 运行 测试同一文件夹中的代码。因此,当我导入 PySimpleGUI 时,旧版本位于较新 PySimpleGUI 的安装路径之前。基本上,我正在导入一个我不记得安装在当前工作目录中的旧版本。由于旧版本没有版本变量,我花了一段时间才意识到我没有导入 pip show PySimpleGUI
报告为从 OS 命令行安装的版本。尴尬。但是,吸取教训。
感谢在此主题中回复的所有人。最终,@acw1668 的建议让我明白了是怎么回事。
我正在尝试起床 运行 PySimpleGUI。我尝试了 运行 以下代码(来自 https://pysimplegui.readthedocs.io/en/latest/#the-quick-tour):
import PySimpleGUI as sg
event, values = sg.Window('Get filename example', [[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), sg.Cancel()] ]).Read()
这是在 Windows 7 盒子上,Python 3.7.1 和 PySimpleGUI 版本 4.18.0。
顺便说一句,我认为这两行应该在 python 命令行下工作。但是,即使我将它们保存为文件(没有其他 python 行,只有换行符和注释),我得到
(Traceback (most recent call last):
File "C:\Users\blorfmorlfle\bin\MoveStagedFiles.py", line 15, in <module>
event, values = sg.Window('Get filename example', [[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), sg.Cancel()] ]).Read()
AttributeError: module 'PySimpleGUI' has no attribute 'Window'
正在搜索类似错误的堆栈溢出,所有结果线程都不同。
FWIW,我已经卸载并重新安装了 PySimpleGUI。
FWIW2,以下工作正常。
sg.Popup('Hello From PySimpleGUI!', 'This is the shortest GUI program ever!')
有什么想法吗?我听说一些 python 版本由于 tkinter 问题而对 PySimpleGUI 有问题。有推荐的版本吗?
我用 python 3.6.8 和 PySimpleGUI 4.18.0 尝试过,使用你提供的相同的两行代码,但它对我也不起作用(内核死了)。
但是,运行 快速浏览 (https://pysimplegui.readthedocs.io/en/latest/#the-quick-tour) 中的另一个示例以更易读的方式简单地提供了代码,对我有用:
import PySimpleGUI as sg
sg.theme('Dark Blue 3') # please make your creations colorful
layout = [ [sg.Text('Filename')],
[sg.Input(), sg.FileBrowse()],
[sg.OK(), sg.Cancel()]]
window = sg.Window('Get filename example', layout)
event, values = window.Read()
window.close()
希望对您有所帮助
几年前我第一次安装 PySimpleGUI,只是为了玩玩它。听说它只有一个 python 文件,我就把它放到了我用来测试代码的文件夹中。
PySimpleGUI 的旧版本现在功能不全,因为它缺少 Window
、theme
等内容。我使用 pip 安装了最新版本。但是,我仍然 运行 测试同一文件夹中的代码。因此,当我导入 PySimpleGUI 时,旧版本位于较新 PySimpleGUI 的安装路径之前。基本上,我正在导入一个我不记得安装在当前工作目录中的旧版本。由于旧版本没有版本变量,我花了一段时间才意识到我没有导入 pip show PySimpleGUI
报告为从 OS 命令行安装的版本。尴尬。但是,吸取教训。
感谢在此主题中回复的所有人。最终,@acw1668 的建议让我明白了是怎么回事。