File: api.html

package info (click to toggle)
python-pywebview 5.0.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 33,680 kB
  • sloc: python: 9,592; javascript: 917; java: 158; cs: 130; sh: 16; makefile: 3
file content (84 lines) | stat: -rw-r--r-- 39,662 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>API | pywebview</title>
    <meta name="generator" content="VuePress 1.9.7">

    <meta name="description" content="Build GUI for your Python program with JavaScript, HTML, and CSS">

    <link rel="preload" href="/3.7/assets/css/0.styles.28a501df.css" as="style"><link rel="preload" href="/3.7/assets/js/app.10a559eb.js" as="script"><link rel="preload" href="/3.7/assets/js/2.0ff7ef1d.js" as="script"><link rel="preload" href="/3.7/assets/js/55.d231c742.js" as="script"><link rel="prefetch" href="/3.7/assets/js/10.f125ec08.js"><link rel="prefetch" href="/3.7/assets/js/11.81fead78.js"><link rel="prefetch" href="/3.7/assets/js/12.0a86c191.js"><link rel="prefetch" href="/3.7/assets/js/13.c09145fc.js"><link rel="prefetch" href="/3.7/assets/js/14.2a7dc35b.js"><link rel="prefetch" href="/3.7/assets/js/15.90c9f36a.js"><link rel="prefetch" href="/3.7/assets/js/16.69b1f4b4.js"><link rel="prefetch" href="/3.7/assets/js/17.956ed884.js"><link rel="prefetch" href="/3.7/assets/js/18.bd6678a0.js"><link rel="prefetch" href="/3.7/assets/js/19.b31e62b7.js"><link rel="prefetch" href="/3.7/assets/js/20.cebc4a71.js"><link rel="prefetch" href="/3.7/assets/js/21.d2041966.js"><link rel="prefetch" href="/3.7/assets/js/22.2a3916f2.js"><link rel="prefetch" href="/3.7/assets/js/23.712fbf84.js"><link rel="prefetch" href="/3.7/assets/js/24.f768e66b.js"><link rel="prefetch" href="/3.7/assets/js/25.69b3e415.js"><link rel="prefetch" href="/3.7/assets/js/26.6619f84a.js"><link rel="prefetch" href="/3.7/assets/js/27.e2a4e1bf.js"><link rel="prefetch" href="/3.7/assets/js/28.abcc819c.js"><link rel="prefetch" href="/3.7/assets/js/29.c379d080.js"><link rel="prefetch" href="/3.7/assets/js/3.749f6582.js"><link rel="prefetch" href="/3.7/assets/js/30.771e8640.js"><link rel="prefetch" href="/3.7/assets/js/31.547a8393.js"><link rel="prefetch" href="/3.7/assets/js/32.778a82c7.js"><link rel="prefetch" href="/3.7/assets/js/33.6ff70f11.js"><link rel="prefetch" href="/3.7/assets/js/34.ae1b5fb4.js"><link rel="prefetch" href="/3.7/assets/js/35.c5555b94.js"><link rel="prefetch" href="/3.7/assets/js/36.d53c471f.js"><link rel="prefetch" href="/3.7/assets/js/37.bbba2d58.js"><link rel="prefetch" href="/3.7/assets/js/38.5eb30036.js"><link rel="prefetch" href="/3.7/assets/js/39.8cac65fe.js"><link rel="prefetch" href="/3.7/assets/js/4.f2c64e71.js"><link rel="prefetch" href="/3.7/assets/js/40.53182a9c.js"><link rel="prefetch" href="/3.7/assets/js/41.19399765.js"><link rel="prefetch" href="/3.7/assets/js/42.41128068.js"><link rel="prefetch" href="/3.7/assets/js/43.660f3959.js"><link rel="prefetch" href="/3.7/assets/js/44.09d5c6f8.js"><link rel="prefetch" href="/3.7/assets/js/45.4a818eab.js"><link rel="prefetch" href="/3.7/assets/js/46.d1621897.js"><link rel="prefetch" href="/3.7/assets/js/47.7f8f8dec.js"><link rel="prefetch" href="/3.7/assets/js/48.f27d4c39.js"><link rel="prefetch" href="/3.7/assets/js/49.4189d401.js"><link rel="prefetch" href="/3.7/assets/js/5.2a771d7d.js"><link rel="prefetch" href="/3.7/assets/js/50.beff8380.js"><link rel="prefetch" href="/3.7/assets/js/51.8a918a6c.js"><link rel="prefetch" href="/3.7/assets/js/52.92d0105f.js"><link rel="prefetch" href="/3.7/assets/js/53.28701cde.js"><link rel="prefetch" href="/3.7/assets/js/54.2b15d6fb.js"><link rel="prefetch" href="/3.7/assets/js/56.7e02bbff.js"><link rel="prefetch" href="/3.7/assets/js/57.61e9e46c.js"><link rel="prefetch" href="/3.7/assets/js/58.cc70e253.js"><link rel="prefetch" href="/3.7/assets/js/59.d3f412e7.js"><link rel="prefetch" href="/3.7/assets/js/6.64e1f3ed.js"><link rel="prefetch" href="/3.7/assets/js/60.f4fd7728.js"><link rel="prefetch" href="/3.7/assets/js/61.cd0f1d68.js"><link rel="prefetch" href="/3.7/assets/js/62.bf000bcc.js"><link rel="prefetch" href="/3.7/assets/js/63.807edde1.js"><link rel="prefetch" href="/3.7/assets/js/64.2b6fe843.js"><link rel="prefetch" href="/3.7/assets/js/7.779cbcff.js"><link rel="prefetch" href="/3.7/assets/js/8.66fb3acb.js"><link rel="prefetch" href="/3.7/assets/js/9.84350af9.js">
    <link rel="stylesheet" href="/3.7/assets/css/0.styles.28a501df.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/3.7/" class="home-link router-link-active"><img src="/3.7/logo-no-text.png" alt="pywebview" class="logo"> <span class="site-name can-hide">pywebview</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/3.7/guide/" class="nav-link router-link-active">
  Guide
</a></div><div class="nav-item"><a href="/3.7/examples/" class="nav-link">
  Examples
</a></div><div class="nav-item"><a href="/3.7/contributing/" class="nav-link">
  Contributing
</a></div><div class="nav-item"><a href="/3.7/blog/" class="nav-link">
  Blog
</a></div><div class="nav-item"><a href="/3.7/CHANGELOG.html" class="nav-link">
  Changelog
</a></div> <a href="https://github.com/r0x0r/pywebview" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/3.7/guide/" class="nav-link router-link-active">
  Guide
</a></div><div class="nav-item"><a href="/3.7/examples/" class="nav-link">
  Examples
</a></div><div class="nav-item"><a href="/3.7/contributing/" class="nav-link">
  Contributing
</a></div><div class="nav-item"><a href="/3.7/blog/" class="nav-link">
  Blog
</a></div><div class="nav-item"><a href="/3.7/CHANGELOG.html" class="nav-link">
  Changelog
</a></div> <a href="https://github.com/r0x0r/pywebview" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>Basics</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/3.7/guide/installation.html" class="sidebar-link">Installation</a></li><li><a href="/3.7/guide/usage.html" class="sidebar-link">Usage</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Development</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/3.7/guide/api.html" aria-current="page" class="active sidebar-link">API</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#webview-create-window" class="sidebar-link">webview.create_window</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#webview-start" class="sidebar-link">webview.start</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#webview-screens" class="sidebar-link">webview.screens</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#webview-token" class="sidebar-link">webview.token</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#height" class="sidebar-link">height</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#width" class="sidebar-link">width</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#on-top" class="sidebar-link">on_top</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#x" class="sidebar-link">x</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#y" class="sidebar-link">y</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#width-2" class="sidebar-link">width</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#height-2" class="sidebar-link">height</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#create-file-dialog" class="sidebar-link">createfiledialog</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#destroy" class="sidebar-link">destroy</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#evaluate-js" class="sidebar-link">evaluate_js</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#get-current-url" class="sidebar-link">getcurrenturl</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#get-elements" class="sidebar-link">get_elements</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#hide" class="sidebar-link">hide</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#load-css" class="sidebar-link">load_css</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#load-html" class="sidebar-link">load_html</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#load-url" class="sidebar-link">load_url</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#minimize" class="sidebar-link">minimize</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#move" class="sidebar-link">move</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#resize" class="sidebar-link">resize</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#restore" class="sidebar-link">restore</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#set-title" class="sidebar-link">set_title</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#show" class="sidebar-link">show</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#toggle-fullscreen" class="sidebar-link">toggle_fullscreen</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#events-closed" class="sidebar-link">events.closed</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#events-closing" class="sidebar-link">events.closing</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#events-loaded" class="sidebar-link">events.loaded</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#events-minimized" class="sidebar-link">events.minimized</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#events-restore" class="sidebar-link">events.restore</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#events-maximized" class="sidebar-link">events.maximized</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#events-resized" class="sidebar-link">events.resized</a></li><li class="sidebar-sub-header"><a href="/3.7/guide/api.html#events-shown" class="sidebar-link">events.shown</a></li></ul></li><li><a href="/3.7/guide/architecture.html" class="sidebar-link">Application architecture</a></li><li><a href="/3.7/guide/debugging.html" class="sidebar-link">Debugging</a></li><li><a href="/3.7/guide/interdomain.html" class="sidebar-link">Interdomain communication</a></li><li><a href="/3.7/guide/freezing.html" class="sidebar-link">Freezing</a></li><li><a href="/3.7/guide/security.html" class="sidebar-link">Security</a></li><li><a href="/3.7/guide/virtualenv.html" class="sidebar-link">Virtual environment</a></li><li><a href="/3.7/guide/renderer.html" class="sidebar-link">Web engine</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="api"><a href="#api" class="header-anchor">#</a> API</h1> <h2 id="webview-create-window"><a href="#webview-create-window" class="header-anchor">#</a> webview.create_window</h2> <div class="language-python extra-class"><pre class="language-python"><code>webview<span class="token punctuation">.</span>create_window<span class="token punctuation">(</span>title<span class="token punctuation">,</span> url<span class="token operator">=</span><span class="token string">''</span><span class="token punctuation">,</span> html<span class="token operator">=</span><span class="token string">''</span><span class="token punctuation">,</span> js_api<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">,</span> width<span class="token operator">=</span><span class="token number">800</span><span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">600</span><span class="token punctuation">,</span> \
                      x<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">,</span> y<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">,</span> resizable<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">,</span> fullscreen<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> \
                      min_size<span class="token operator">=</span><span class="token punctuation">(</span><span class="token number">200</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">,</span> hidden<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> frameless<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> \
                      minimized<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> on_top<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> confirm_close<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> \
                      background_color<span class="token operator">=</span><span class="token string">'#FFF'</span><span class="token punctuation">,</span> text_select<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span>
</code></pre></div><p>Create a new <em>pywebview</em> window and returns its instance. Window is not shown until the GUI loop is started. If the function is invoked during the GUI loop, the window is displayed immediately.</p> <ul><li><code>title</code> - Window title</li> <li><code>url</code> - URL to load. If the URL does not have a protocol prefix, it is resolved as a path relative to the application entry point. Alternatively a WSGI server object can be passed to start a local web server.</li> <li><code>html</code> - HTML code to load. If both URL and HTML are specified, HTML takes precedence.</li> <li><code>js_api</code> - Expose a python object to the DOM of the current <code>pywebview</code> window. Methods of  the <code>js_api</code> object can be executed from Javascript by calling <code>window.pywebview.api.&lt;methodname&gt;(&lt;parameters&gt;)</code>. Please note that the calling Javascript function receives a promise that will contain the return value of the python function. Only basic Python objects (like int, str, dict, ...) can be returned to Javascript.</li> <li><code>width</code> - Window width. Default is 800px.</li> <li><code>height</code> - Window height. Default is 600px.</li> <li><code>x</code> - Window x coordinate. Default is centered.</li> <li><code>y</code> - Window y coordinate. Default is centered.</li> <li><code>resizable</code> - Whether window can be resized. Default is True</li> <li><code>fullscreen</code> - Start in fullscreen mode. Default is False</li> <li><code>min_size</code> - a (width, height) tuple that specifies a minimum window size. Default is 200x100</li> <li><code>hidden</code> - Create a window hidden by default. Default is False</li> <li><code>frameless</code> - Create a frameless window. Default is False.</li> <li><code>easy_drag</code> - Easy drag mode for frameless windows. Window can be moved by dragging any point. Default is True. Note that easy_drag has no effect with normal windows. To control dragging on an element basis, see <a href="/3.7/guide/api.html#drag-area">drag area</a> for details.</li> <li><code>minimized</code> - Start in minimized mode</li> <li><code>on_top</code> - Set window to be always on top of other windows. Default is False.</li> <li><code>confirm_close</code> - Whether to display a window close confirmation dialog. Default is False</li> <li><code>background_color</code> - Background color of the window displayed before WebView is loaded. Specified as a hex color. Default is white.</li> <li><code>transparent</code> - Create a transparent window. Not supported on Windows. Default is False. Note that this setting does not hide or make window chrome transparent. To hide window chrome set <code>frameless</code> to True.</li> <li><code>text_select</code> - Enables document text selection. Default is False. To control text selection on per element basis, use <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/user-select" target="_blank" rel="noopener noreferrer">user-select<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> CSS property.</li></ul> <h2 id="webview-start"><a href="#webview-start" class="header-anchor">#</a> webview.start</h2> <div class="language-python extra-class"><pre class="language-python"><code>webview<span class="token punctuation">.</span>start<span class="token punctuation">(</span>func<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">,</span> args<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">,</span> localization<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> gui<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">,</span> debug<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> \
              http_server<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> user_agent<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">)</span>
</code></pre></div><p>Start a GUI loop and display previously created windows. This function must be called from a main thread.</p> <ul><li><code>func</code> - function to invoke upon starting the GUI loop.</li> <li><code>args</code> - function arguments. Can be either a single value or a tuple of values.</li> <li><code>localization</code> - a dictionary with localized strings. Default strings and their keys are defined in localization.py</li> <li><code>gui</code> - force a specific GUI. Allowed values are <code>cef</code>, <code>qt</code> or <code>gtk</code> depending on a platform. See <a href="/3.7/guide/renderer.html">Renderer</a> for details.</li> <li><code>debug</code> - enable debug mode. See <a href="/3.7/guide/debugging.html">Debugging</a> for details.</li> <li><code>http_server</code> - enable built-in HTTP server. If enabled, local files will be served using a local HTTP server on a random port. For each window, a separate HTTP server is spawned. This option is ignored for non-local URLs.</li> <li><code>user_agent</code> - change user agent string. Not supported in EdgeHTML.</li></ul> <h3 id="examples"><a href="#examples" class="header-anchor">#</a> Examples</h3> <ul><li><a href="/3.7/examples/open_url.html">Simple window</a></li> <li><a href="/3.7/examples/multiple_windows.html">Multi-window</a></li></ul> <h2 id="webview-screens"><a href="#webview-screens" class="header-anchor">#</a> webview.screens</h2> <div class="language-python extra-class"><pre class="language-python"><code>webview<span class="token punctuation">.</span>screens
</code></pre></div><p>Return a list of available displays (as <code>Screen</code> objects) with the primary display as the first element of the list.</p> <h3 id="examples-2"><a href="#examples-2" class="header-anchor">#</a> Examples</h3> <ul><li><a href="/3.7/examples/screens.html">Simple window</a></li></ul> <h2 id="webview-token"><a href="#webview-token" class="header-anchor">#</a> webview.token</h2> <div class="language-python extra-class"><pre class="language-python"><code>webview<span class="token punctuation">.</span>token
</code></pre></div><p>A CSRF token property unique to the session. The same token is exposed as <code>window.pywebview.token</code>. See <a href="/3.7/guide/security.html">Security</a> for usage details.</p> <h1 id="screen-object"><a href="#screen-object" class="header-anchor">#</a> Screen object</h1> <p>Represents a display found on the system.</p> <h2 id="height"><a href="#height" class="header-anchor">#</a> height</h2> <div class="language-python extra-class"><pre class="language-python"><code>screen<span class="token punctuation">.</span>height
</code></pre></div><p>Get display height.</p> <h2 id="width"><a href="#width" class="header-anchor">#</a> width</h2> <div class="language-python extra-class"><pre class="language-python"><code>screen<span class="token punctuation">.</span>width
</code></pre></div><p>Get display width.</p> <h1 id="window-object"><a href="#window-object" class="header-anchor">#</a> Window object</h1> <p>Represents a window that hosts webview. <code>window</code> object is returned by <code>create_window</code> function.</p> <h2 id="on-top"><a href="#on-top" class="header-anchor">#</a> on_top</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>on_top
</code></pre></div><p>Get or set whether the window is always on top</p> <h2 id="x"><a href="#x" class="header-anchor">#</a> x</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>x
</code></pre></div><p>Get X coordinate of the top-left corrner of the window</p> <h2 id="y"><a href="#y" class="header-anchor">#</a> y</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>y
</code></pre></div><p>Get Y coordinate of the top-left corrner of the window</p> <h2 id="width-2"><a href="#width-2" class="header-anchor">#</a> width</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>width
</code></pre></div><p>Get width of the window</p> <h2 id="height-2"><a href="#height-2" class="header-anchor">#</a> height</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>height
</code></pre></div><p>Get height of the window</p> <h2 id="create-file-dialog"><a href="#create-file-dialog" class="header-anchor">#</a> create_file_dialog</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>create_file_dialog<span class="token punctuation">(</span>dialog_type<span class="token operator">=</span>OPEN_DIALOG<span class="token punctuation">,</span> directory<span class="token operator">=</span><span class="token string">''</span><span class="token punctuation">,</span> allow_multiple<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">,</span> save_filename<span class="token operator">=</span><span class="token string">''</span><span class="token punctuation">,</span> file_types<span class="token operator">=</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>`
</code></pre></div><p>Create an open file (<code>webview.OPEN_DIALOG</code>), open folder (<code>webview.FOLDER_DIALOG</code>) or save file (<code>webview.SAVE_DIALOG</code>) dialog.</p> <p>Return a tuple of selected files, None if cancelled.</p> <ul><li><code>allow_multiple=True</code> enables multiple selection.</li> <li><code>directory</code> Initial directory.</li> <li><code>save_filename</code> Default filename for save file dialog.</li> <li><code>file_types</code> A tuple of supported file type strings in the open file dialog. A file type string must follow this format <code>&quot;Description (*.ext1;*.ext2...)&quot;</code>.</li></ul> <p>If the argument is not specified, then the <code>&quot;All files (*.*)&quot;</code> mask is used by default. The 'All files' string can be changed in the localization dictionary.</p> <h3 id="examples-3"><a href="#examples-3" class="header-anchor">#</a> Examples</h3> <ul><li><a href="/3.7/examples/open_file_dialog.html">Open-file dialog</a></li> <li><a href="/3.7/examples/save_file_dialog.html">Save-file dialog</a></li></ul> <h2 id="destroy"><a href="#destroy" class="header-anchor">#</a> destroy</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>destroy<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><p>Destroy the window.</p> <p><a href="/3.7/examples/destroy_window.html">Example</a></p> <h2 id="evaluate-js"><a href="#evaluate-js" class="header-anchor">#</a> evaluate_js</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>evaluate_js<span class="token punctuation">(</span>script<span class="token punctuation">,</span> callback<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">)</span>
</code></pre></div><p>Execute Javascript code. The last evaluated expression is returned. If callback function is supplied, then promises are resolved and the callback function is called with the result as a parameter. Javascript types are converted to Python types, eg. JS objects to dicts, arrays to lists, undefined to None. Note that due implementation limitations the string 'null' will be evaluated to None.
You must escape \n and \r among other escape sequences if they present in Javascript code. Otherwise they get parsed by Python. r'strings' is a recommended way to load Javascript. For GTK WebKit2 versions older than 2.22, there is a limit of about ~900 characters for a value returned by <code>evaluate_js</code>.</p> <h2 id="get-current-url"><a href="#get-current-url" class="header-anchor">#</a> get_current_url</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>get_current_url<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><p>Return the current URL. None if no url is loaded.</p> <p><a href="/3.7/examples/get_current_url.html">Example</a></p> <h2 id="get-elements"><a href="#get-elements" class="header-anchor">#</a> get_elements</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>get_elements<span class="token punctuation">(</span>selector<span class="token punctuation">)</span>
</code></pre></div><p>Return the serialized DOM element by its selector. None if no element matches. For GTK you must have WebKit2 2.22 or greater to use this function.</p> <p><a href="/3.7/examples/get_elements.html">Example</a></p> <h2 id="hide"><a href="#hide" class="header-anchor">#</a> hide</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>hide<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><p>Hide the window.</p> <p><a href="/3.7/examples/show_hide.html">Example</a></p> <h2 id="load-css"><a href="#load-css" class="header-anchor">#</a> load_css</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>load_css<span class="token punctuation">(</span>css<span class="token punctuation">)</span>
</code></pre></div><p>Load CSS as a string.</p> <p><a href="/3.7/examples/css_load.html">Example</a></p> <h2 id="load-html"><a href="#load-html" class="header-anchor">#</a> load_html</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>load_html<span class="token punctuation">(</span>content<span class="token punctuation">,</span> base_uri<span class="token operator">=</span>base_uri<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre></div><p>Load HTML code. Base URL for resolving relative URLs is set to the directory the program is launched from. Note that you cannot use hashbang anchors when HTML is loaded this way.</p> <p><a href="/3.7/examples/html_load.html">Example</a></p> <h2 id="load-url"><a href="#load-url" class="header-anchor">#</a> load_url</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>load_url<span class="token punctuation">(</span>url<span class="token punctuation">)</span>
</code></pre></div><p>Load a new URL.</p> <p><a href="/3.7/examples/change_url.html">Example</a></p> <h2 id="minimize"><a href="#minimize" class="header-anchor">#</a> minimize</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>minimize<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><p>Minimize window.</p> <p><a href="/3.7/examples/minimize.html">Example</a></p> <h2 id="move"><a href="#move" class="header-anchor">#</a> move</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>move<span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">)</span>
</code></pre></div><p>Move window to a new position.</p> <p><a href="/3.7/examples/move_window.html">Example</a></p> <h2 id="resize"><a href="#resize" class="header-anchor">#</a> resize</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>resize<span class="token punctuation">(</span>width<span class="token punctuation">,</span> height<span class="token punctuation">,</span> fix_point<span class="token operator">=</span>FixPoint<span class="token punctuation">.</span>NORTH <span class="token operator">|</span> FixPoint<span class="token punctuation">.</span>WEST<span class="token punctuation">)</span>
</code></pre></div><p>Resize window. Optional parameter fix_point specifies in respect to which point the window is resized. The parameter accepts values of the <code>webview.window.FixPoint</code> enum (<code>NORTH</code>, <code>SOUTH</code>, <code>EAST</code>, <code>WEST</code>)</p> <p><a href="/3.7/examples/minimize.html">Example</a></p> <h2 id="restore"><a href="#restore" class="header-anchor">#</a> restore</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>restore<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><p>Restore minimized window.</p> <p><a href="/3.7/examples/minimize.html">Example</a></p> <h2 id="set-title"><a href="#set-title" class="header-anchor">#</a> set_title</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>set_title<span class="token punctuation">(</span>title<span class="token punctuation">)</span>
</code></pre></div><p>Change the title of the window.</p> <p><a href="/3.7/examples/window_title_change.html">Example</a></p> <h2 id="show"><a href="#show" class="header-anchor">#</a> show</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>show<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><p>Show the window if it is hidden. Has no effect otherwise</p> <p><a href="/3.7/examples/show_hide.html">Example</a></p> <h2 id="toggle-fullscreen"><a href="#toggle-fullscreen" class="header-anchor">#</a> toggle_fullscreen</h2> <div class="language-python extra-class"><pre class="language-python"><code>window<span class="token punctuation">.</span>toggle_fullscreen<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre></div><p>Toggle fullscreen mode on the active monitor.</p> <p><a href="/3.7/examples/toggle_fullscreen.html">Example</a></p> <h1 id="events"><a href="#events" class="header-anchor">#</a> Events</h1> <p>Window object has a number of lifecycle events. To subscribe to an event, use the <code>+=</code> syntax, e.g. <code>window.events.loaded += func</code>. The func will be invoked, when event is fired. Duplicate subscriptions are ignored and function is invoked only once for duplicate subscribers. To unsubscribe <code>window.events.loaded -= func</code>.</p> <h2 id="events-closed"><a href="#events-closed" class="header-anchor">#</a> events.closed</h2> <p>Event fired just before pywebview window is closed.</p> <p><a href="/3.7/examples/events.html">Example</a></p> <h2 id="events-closing"><a href="#events-closing" class="header-anchor">#</a> events.closing</h2> <p>Event fired when pywebview window is about to be closed. If confirm_quit is set, then this event is fired before the close confirmation is displayed. If event handler returns False, the close operation will be cancelled.</p> <p><a href="/3.7/examples/events.html">Example</a></p> <h2 id="events-loaded"><a href="#events-loaded" class="header-anchor">#</a> events.loaded</h2> <p>Event fired when DOM is ready.</p> <p><a href="/3.7/examples/events.html">Example</a></p> <h2 id="events-minimized"><a href="#events-minimized" class="header-anchor">#</a> events.minimized</h2> <p>Event fired when window is minimized.</p> <p><a href="/3.7/examples/events.html">Example</a></p> <h2 id="events-restore"><a href="#events-restore" class="header-anchor">#</a> events.restore</h2> <p>Event fired when window is restored.</p> <p><a href="/3.7/examples/events.html">Example</a></p> <h2 id="events-maximized"><a href="#events-maximized" class="header-anchor">#</a> events.maximized</h2> <p>Event fired when window is maximized (fullscreen on macOS)</p> <h2 id="events-resized"><a href="#events-resized" class="header-anchor">#</a> events.resized</h2> <p>Event fired when pywebview window is resized. Event handler can either have no or accept (width, height) arguments.</p> <p><a href="/3.7/examples/events.html">Example</a></p> <h2 id="events-shown"><a href="#events-shown" class="header-anchor">#</a> events.shown</h2> <p>Event fired when pywebview window is shown.</p> <p><a href="/3.7/examples/events.html">Example</a></p> <h1 id="dom-events"><a href="#dom-events" class="header-anchor">#</a> DOM events</h1> <p><em>pywebview</em> exposes a <code>window.pywebviewready</code> DOM event that is fired when <code>window.pywebview</code> is created.</p> <p><a href="/3.7/examples/js_api.html">Example</a></p> <h1 id="drag-area"><a href="#drag-area" class="header-anchor">#</a> Drag area</h1> <p>With a frameless <em>pywebview</em> window, A window can be moved or dragged by adding a special class called <code>pywebview-drag-region</code> in your html</p> <div class="language-html extra-class"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">'</span>pywebview-drag-region<span class="token punctuation">'</span></span><span class="token punctuation">&gt;</span></span>This div element can be used to moved or drag your window like a native OS window<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><p>The magic class name can be overriden by re-assigning the <code>webview.DRAG_REGION_SELECTOR</code> constant.</p> <p><a href="/3.7/examples/js_api.html">Example</a></p></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/r0x0r/pywebview/edit/docs/docs/guide/api.md" target="_blank" rel="noopener noreferrer">Help us improve this page!</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      <a href="/3.7/guide/usage.html" class="prev">
        Usage
      </a></span> <span class="next"><a href="/3.7/guide/architecture.html">
        Application architecture
      </a>
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/3.7/assets/js/app.10a559eb.js" defer></script><script src="/3.7/assets/js/2.0ff7ef1d.js" defer></script><script src="/3.7/assets/js/55.d231c742.js" defer></script>
  </body>
</html>