3

The input fields are editable, I can insert a value with keys on keyboard and inc/dec values when running the source from Terminal with Python3.

But, the moment I compile it successfully using PyInstaller, it behaves weird:

The input fields simply not taking over whatever you fill in there. The console however takes over the key input. When I want to use the arrows to increase or decrease value, they simply not react or react wonky. Pointing the cursor on the down arrow to decrease, doesn't do anything for ex. Pointing the cursor on the upper arrow to increase, makes it hit the down arrow instead.

Example showing here: https://youtu.be/Wyx3FOlWNuA

When I use CEF instead by altering last line in main.py from:

webview.start()

to

webview.start(gui='cef')

...The arrows behave correctly. But key input, still not able to.

Tried on macOS El Capitan + Catalina, using Python 3.8.5 & Python 3.6.8 / PyInstaller 4.1

On Windows + Linux, all function properly.

Is this some macOS limitation/bug?

I'm aware of: https://github.com/r0x0r/pywebview/issues/66 But I'm not using a virtual environment.

I'm also aware of: Python webview GUI: hover effects and key input not working (using pywebview) But since no one answered, and my comment got removed asking if he got it solved by now, hereby a new thread.

Code index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example</title>
</head>
<body>
    <input>
    <input type='number'>
</body>
</html>

Code main.py:

import webview

if __name__ == '__main__':
    webview.create_window('Example', 'index.html')
    webview.start()

Code main.spec:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['main.py'],
             pathex=[],
             binaries=[],
             datas=[('index.html', '.')],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='main',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True)

Also tried to compile as an .app, using https://pyinstaller.readthedocs.io/en/stable/spec-files.html#spec-file-options-for-a-mac-os-x-bundle, same outcome. Also tried to compile with --noconsole, same outcome.

Bas Curtiz
  • 73
  • 8

1 Answers1

1

The only thing that worked for me was to disable the console setting, console=False in the EXE() command. I believe CLI arguments, such as --noconsole, didn't work for you because they are be overriden by the .spec file. Not sure if some console + windowed output combination is at all possible in OS X currently - we plan to deploy a separate script that would launch the terminal and run something like ./app.

juod
  • 440
  • 3
  • 8
  • Thanks! I had to set `debug=False` + `console=False` + compile as .app to make the input function within the webview/gui. But... We want to use the CLI/Terminal for the log. So if you came up with a workaround (so we can still use the terminal to show info), please post it here! – Bas Curtiz Dec 04 '20 at 00:45