pythontkinterpysimplegui

AttributeError: module 'PySimpleGUI' has no attribute 'Window'


I am trying to get up and running with PySimpleGUI. I tried running the following code (from 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()

This is on a Windows 7 box, with Python 3.7.1, and PySimpleGUI version 4.18.0.

BTW, those two lines should work from a python command line, I think. But, even if I save them as a file (with no other python lines, just newlines and comments), I get

(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'

Searching stack overflow for similar errors, all the results threads were different.

FWIW, I have uninstalled and reinstalled PySimpleGUI.

FWIW2, the following works fine.

sg.Popup('Hello From PySimpleGUI!', 'This is the shortest GUI program ever!')

Any thoughts? I have heard some python releases are problematic for PySimpleGUI because of tkinter issues. Is there a recommended release?


Solution

  • I first installed PySimpleGUI a couple years ago, just to play with it. Having heard that it was just one python file, I just dropped it in a folder I was using for testing code.

    That older version of PySimpleGUI isn't fully functional now, as it's missing things like Window, theme, etc. I installed the latest using pip. But, I have still been running test code from the same folder. So, when I imported PySimpleGUI, the old version was ahead of the newer PySimpleGUI's install path. Basically, I was importing an older version that I didn't remember was installed in the current working directory. Since the old version didn't have a version variable, it took a while to realize that I wasn't importing the version that pip show PySimpleGUI was reporting as installed from the OS command line. Embarrassing. But, lesson learned.

    Thank you to everyone who responded in this thread. Eventually, @acw1668's suggestion made me realize what was going on.