Reputation: 11
I am trying to show a local html page in pywebview in a maximized screen by default , I have tried all methods I could find but it didnt work. here is my code :
from flask import Flask, send_from_directory
import threading
import webview
import os
...
webview.create_window('My React App', url='http://127.0.0.1:5000')
webview.start()
here is what I have tried so far:
I tried Fullscreen flag as True but it will only show the webview in full screen and the windows frame around the webview disappears, I am trying to show it as a maximized window with "close , minimize etc" buttons
webview.create_window('My React App', url='http://127.0.0.1:5000', fullscreen=True)
Then I tried to get the screen size and define that as height and width , it maximized the window but it showed 10 pixel gap on the right and left side of the window :
screen_width = user32.GetSystemMetrics(0)
screen_height = user32.GetSystemMetrics(1)
root.geometry(f"{screen_width}x{screen_height}")
webview.create_window("My React App",url="http://127.0.0.1:5000",width=screen_width, height=screen_height)
How can I make it so , that it launched the webview in a maximized window by default?
Upvotes: 0
Views: 1749
Reputation: 1
If you want to see the controls windows panel:
# It doesn't work in Jupyter ###
# It works in Pycharm #
import webview
import ctypes
def create_window():
# Create a maximized window
window = webview.create_window(
"My Maximized App",
"https://example.com/", # Replace with your local HTML file path
resizable=True,
#frameless=False # Ensure the window has a frame with controls
)
# Maximize the window
def maximize_window():
user32 = ctypes.windll.user32
hwnd = user32.GetForegroundWindow()
user32.ShowWindow(hwnd, 3) # SW_MAXIMIZE
webview.windows[0].events.loaded += maximize_window
webview.start()
if __name__ == "__main__":
create_window()
Upvotes: 0
Reputation: 1
You can use toggle_fullscreen()
function to Maximize and Restore down the window.
To open maximized window by default, you can first create a window and then maximize it.
Here is a code:
from flask import Flask, send_from_directory
import threading
import webview
import os
def minimize():
window.minimize()
def maximize():
window.toggle_fullscreen()
def close():
window.destroy()
...
window = webview.create_window('My React App', url='http://127.0.0.1:5000')
webview.start(func=maximize)
This code will open a window in maximized form
Upvotes: 0
Reputation: 1
In webview, maximize functionality is not available by default.
You can try fullscreen
option of the webview.create_window()
method.
from flask import Flask, send_from_directory
import threading
import webview
import os
...
webview.create_window('My React App', url='http://127.0.0.1:5000', fullscreen=True)
webview.start()
Upvotes: 0