我正试着和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()这是在Windows7框上,有Python3.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带来了问题。有推荐的释放吗?
发布于 2020-04-08 04:11:57
我第一次安装PySimpleGUI是在几年前,就是为了玩它。在听说它只是一个python文件之后,我就把它放到了一个用于测试代码的文件夹中。
那个旧版本的PySimpleGUI现在还没有完全运行,因为它缺少Window、theme等东西。我安装了最新的pip。但是,我仍然在同一个文件夹中运行测试代码。因此,当我导入PySimpleGUI时,旧版本领先于较新的PySimpleGUI的安装路径。基本上,我是在导入一个我不记得安装在当前工作目录中的旧版本。由于旧版本没有版本变量,所以我花了很长时间才意识到,我并没有导入pip show PySimpleGUI从OS命令行中报告的版本。太尴尬了。但是,吸取了教训。
感谢所有在这篇文章中做出回应的人。最后,@ was 1668的建议让我意识到发生了什么。
发布于 2020-04-07 19:14:51
我用python3.6.8和PySimpleGUI 4.18.0用您提供的两行代码尝试了它,但它对我也不起作用(Kernel死了)。
但是,在快速浏览(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()我希望这能帮上忙
https://stackoverflow.com/questions/61087422
复制相似问题