Create a directly-executable cross-platform GUI app using Python

前端 未结 12 2270
予麋鹿
予麋鹿 2020-11-22 10:52

Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows

12条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 11:20

    PySimpleGUI wraps tkinter and works on Python 3 and 2.7. It also runs on Qt, WxPython and in a web browser, using the same source code for all platforms.

    You can make custom GUIs that utilize all of the same widgets that you find in tkinter (sliders, checkboxes, radio buttons, ...). The code tends to be very compact and readable.

    #!/usr/bin/env python
    import sys
    if sys.version_info[0] >= 3:
        import PySimpleGUI as sg
    else:
        import PySimpleGUI27 as sg
    
    layout = [[ sg.Text('My Window') ],
              [ sg.Button('OK')]]
    
    window = sg.Window('My window').Layout(layout)
    button, value = window.Read()
    

    As explained in the PySimpleGUI Documentation, to build the .EXE file you run:

    pyinstaller -wF MyGUIProgram.py

提交回复
热议问题