Fork me on GitHub

Python and GUI

Полезные ссылки

Установка Gooey

pip install Gooey

Установка PySimpleGUI

 sudo apt install python3-tk
 pip3 install pysimplegui

Решение проблем при установке Gooey

при установке библиотеки gooey выдается ошибка компиляции wxPython, нужно выполнить след команды:

pip3 install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 wxPython  

pip3 install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-20.04/ wxPython

sudo apt-get install python3.6-dev

Если ругается на отсутствие GTK3:

sudo apt-get install libgtk-3-dev

Для установки в Ubuntu 20.04 помогло установить wxPython установка следующие библиотеки:

sudo apt install python3-pip make gcc libgtk-3-dev libgstreamer-gl1.0-0 freeglut3 freeglut3-dev python3-gst-1.0 libglib2.0-dev ubuntu-restricted-extras libgstreamer-plugins-base1.0-dev
sudo apt-get install libwxbase3.0-0v5

Pyinstaller and Gooey

Exception in thread Thread-1:
Traceback (most recent call last):
  File "threading.py", line 917, in _bootstrap_inner
  File "threading.py", line 865, in run
  File "lib\site-packages\gooey\gui\processor.py", line 71, in _forward_stdout
  File "lib\site-packages\gooey\gui\processor.py", line 84, in _extract_progress
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 16: invalid continuation byte

Решение: (https://github.com/chriskiehl/Gooey/issues/520)

Following this great resource, it seems that using the codecs module to redirect stdout and stderr works.

  1. Forget about the modification of processor.py
  2. Add near the top of your (main) script:
import codecs

if sys.stdout.encoding != 'UTF-8':
    sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')
if sys.stderr.encoding != 'UTF-8':
    sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict')

If this works for you, that could be the solution.

Wooey

  • Install

bash pip install wooey

  • A Wooey only project

  • wooify -p ProjectName

  • Follow the instructions at the end of the bootstrapper to create the admin user and access the admin page

  • Login to the admin page wherever the project is being hosted (locally this would be localhost:8000/admin)
python manage.py createsuperuser 
python manage.py runserver

EEL

  • установка зависимости:
pip install eel
  • в корне проекта файл start.py
import eel
import random as rnd
values = ["Привет", "Привет, мир", "Вывод", "Test EEL"]
@eel.expose
def testfunc():
   global values
   return rnd.choice(values)
eel.init("front")
eel.start("index.html") 
  • в папке front создадим файл index.hrml
<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <title>Title</title>
   <script src="eel.js"></script>
</head>
<body>
   <p id="text-p">Hello</p>
   <button id="click-elem">Click</button>
   <script>
       document.getElementById("click-elem").onclick = async () => {
          document.getElementById("text-p").textContent = await eel.testfunc()();
       }
   </script>
</body>
</html>

всё можно запускать файл start.py

social