PywebView full screen mode implementation program exits

tags: Python

After using pywebview to start the program with the full screen mode, it is no window border. Of course, there is no shutdown button, you can draw a button in the front page page, call the custom API method with the JS, refer to the problem on Stackoverflow:

https://stackoverflow.com/questions/65279193/how-to-close-pywebview-window-from-javascript-using-pywebview-api

Directly on the code, see the comment

import sqlite3
import webview
from flask import Flask, render_template

app = Flask(__name__)

conn = sqlite3.connect('data.db', check_same_thread=False)
c = conn.cursor()


@app.route('/')
def index():
    # Random drawn
    data = []
    cursor = c.execute('select * from tiku order by random() limit 2')
    # cursor = c.execute('select * from tiku where id = 62 or id = 67')
    for row in cursor:
        data.append({
            'id': row[0],
            'title': row[1],
            'answer': row[2]
        })
    return render_template('index.html', data=data)


# Define the API class definition to pass to the front-end JS, define internal properties _Window and set_window () methods to pass the Window objects in WebView you want to operate.
class Api:
    def __init__(self):
        self._window = None

    def set_window(self, window):
        self._window = window

    def quit(self):
        self._window.destroy()


def start_app():
    api = Api()
    window = webview.create_window(
        title='Tropical Procedure',
        url=app,
        confirm_close=True,
        fullscreen=True,
        js_api=api,
    )
    api.set_window(window)

    cn = {
        'global.quitConfirmation': u'confirm to close?'
    }

    webview.start(localization=cn, debug=True, gui='cef')


if __name__ == '__main__':
    # app.run(port=8000, debug=True)
    start_app()

Front-end call

// Call the PywebView's API
$("#exit").click(function () {
      pywebview.api.quit();
})

Intelligent Recommendation

VUE full screen / exit full screen, ESC monitor exits full screen

template: js:   Note: Monitoring the ESC to exit full screen, if you use monitor KeyDown events (key.code === 27), the button will not be monitored when the full screen will not be recorded, so i...

[Solve full-screen ESC and F11 issues] VUE implements full screen and exits full screen function, realizing a full-screen function of an element

Full screen function It has been solved because the user presses the full screen after entering the full screen, and the user is quit the full screen. The button does not take effect. Solve the full s...

The front-end js makes the browser window full screen and exits-when the browser is full screen, monitor exits the full screen through the esc button (there are related processing on the page when exiting the full screen)

vue project The project is divided into top navigation, side navigation, and mainContent area on the right The requirement is to make one of the pages of the project have full screen function and hide...

Google Chrome crashes when video playback full screen exits

Recently, I was using Google Chrome to watch the full screen of the Flash video. When I quit, the video computer is suspended (the video sound is still there, but the screen has been frozen when I qui...

When ESC exits the full screen, the button description changes synchronously

When you exit the full screen with ESC, the system full screen button description will change synchronously. Disadvantages: When you use F11 to expand the full screen or exit the full screen, it is no...

More Recommendation

[IOS] video full screen exits, the navigation bar is offset by 20

Problem Description When the video full-screen full-screen playback (call the original player play), then click the completion of the left upper corner, the navigation bar is shifted upwards 20. As sh...

H5 page implementation open true full screen mode, compatible version

This article will share a JS full screen method with good compatibility full screen...

Android full screen program

Android full screen program For the full-screen scheme launched by the app, it is found that many methods are mainly for the re-immersion status bar, not the most appropriate. until this scenario: 1 S...

Python -Pywebview, Flaskwebgui to send desktop program

pywebview Packet Official article Case Practice flaskwebgui Pack: PIP Install FLASKWEBGUI github: Example: structure:...

Android full screen mode

The activity can be re-executed as follows:  ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top