Answer the question
In order to leave comments, you need to log in
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
Tkinter is not a third party library, it is included in the standard Python distribution.
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 ...
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()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question