Skip to content

Instantly share code, notes, and snippets.

@techtonik
Last active October 27, 2023 10:33
Show Gist options
  • Save techtonik/d02baae340d1cd5f8682 to your computer and use it in GitHub Desktop.
Save techtonik/d02baae340d1cd5f8682 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