V
V
Vlad2022-03-01 22:09:20
Python
Vlad, 2022-03-01 22:09:20

How to create a window/full application in pure Python?

I would like to create a window (which can also be supplemented with widgets and blackjack) in pure Python/Cython. Without the use of third-party libraries like Tkinter, only the built-in os/sys/math, etc.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2022-03-01
@sergey-gornostaev

Tkinter is not a third party library, it is included in the standard Python distribution.

V
Vindicar, 2022-03-01
@Vindicar

If on pure python without tkinter, then there is no cross-platform solution.
Under Windows - ctypes + windows api, but this is a very, very painful solution.
Under niks... that's honest, I fz. I won't be surprised if there you need to bind to a specific window manager ...

R
Ross Alex, 2022-03-02
@Wacdis

I did not suffer, I took webview and everything is simple and cross-platform!

# https://pywebview.flowrl.com
import webview
import threading
import time
import sys
import random

html = """
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"></head><body>
    <a href="" id="b1">Button</a>
  <script>
    document.querySelector('#b1').addEventListener('click', (ev) => {
      ev.preventDefault();
      pywebview.api.btnAClick().then((r) => {
        document.querySelector('#b1').style.color = '#FFF000';
      });
    });
  </script>
</body></html>
"""

class MyApi:
  def __init__(self):
    self.cancel_heavy_stuff_flag = False

  def btnAClick(self):
    response = {
      'error': 0,
      'message': 'https://google.com/'
    }
    return response

if __name__ == '__main__':
  api = MyApi()
  window = webview.create_window('Example', html=html, js_api=api)
  webview.start()

If not a secret, then why such a solution is needed?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question