Skip to content

Instantly share code, notes, and snippets.

@Abdur-rahmaanJ
Forked from techtonik/webview.py
Created July 29, 2019 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Abdur-rahmaanJ/7add1338045a666815385fbfc69e2983 to your computer and use it in GitHub Desktop.
Save Abdur-rahmaanJ/7add1338045a666815385fbfc69e2983 to your computer and use it in GitHub Desktop.
View HTML content in Python with PySide
"""
Placed into public domain by
anatoly techtonik <techtonik@gmail.com>
Show HTML in GUI window through PyQt4/PySide.
[ ] position window at the center of the screen
(right now it is middle bottom)
[ ] implement lazy loading for PyQt4/PySide
"""
import sys
try:
from PySide import QtGui, QtWebKit
except ImportError:
try:
from PyQt4 import QtGui, QtWebKit
except ImportError:
sys.stderr.write("WebView requires PySide or PyQt4 for GUI window")
def viewhtml(html):
app = QtGui.QApplication([])
view = QtWebKit.QWebView()
view.setHtml(html)
view.show()
app.exec_()
def viewurl(url):
app = QtGui.QApplication([])
view = QtWebKit.QWebView()
view.load(url)
view.show()
app.exec_()
viewhtml('''<b>WebView Public Gist</b>''')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment