PyQt5 How To Close Application Using HTML Button

In my PyQt5 browser window I've loaded HTML and JavaScript. I've Included a button in the HTML which should close the Python-Application using vanilla JavaScript. Here is my Python code which makes the window and loads the HTML-File:

import sys
import os
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.browser = QWebEngineView()
        config_name = 'data_files/init.html'
        if getattr(sys, 'frozen', False):
            application_path = os.path.dirname(sys.executable)
        elif __file__:
            application_path = os.path.dirname(__file__)
        config_path = os.path.join(application_path, config_name)
        self.browser.load(QUrl().fromLocalFile(config_path))
        self.setCentralWidget(self.browser)
        self.showMaximized()


app = QApplication(sys.argv)
QApplication.setApplicationName('v0.1')
window = MainWindow()
app.exec_()

And In my HTML I have this:

<button onclick="exitApplication()">Exit</button>

<script>
    function exitApplication() {
        // How can I tell Python to call self.close() ??
    }
</script>

As I said I want to close the Application using the button inside the HTML. I've looked at various sources but I could never find anything that helped me out or was just too confusing.

How can I close the Application when calling the exitApplication()-Function?



from Recent Questions - Stack Overflow https://ift.tt/39K39OE
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation