How to render HTML on PySimpleGUIQt?

Viewed 59

I tried using Jason Yang's code, posted here: Rendering HTML in PySimpleGUI?, and modifying it to work with PySimpleGUIQt, but I couldn't get it to work, searchings at the PySimpleGUIQt.py file, for such elements to replace with in the code, but it didn't work for me.

I searched for QWebEnginePage/QWebEngineView on the PySimpleGUIQt.py file, but it doesn't show up there.

Here is my best try:

import PySimpleGUIQt as sg
from PySide2.QtWebEngineWidgets import QWebEngineView
html '''
<canvas id="myCanvas" width="100" height="25"">
Not supported</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(10,10,5,0,2*Math.PI);
ctx.stroke();
</script>
'''
layout_advertise = [
[sg.Multiline(
    size=(50, 5),
    text_color='white',
    background_color='green',
    disabled=True,
    key='Advertise')],
]
layout = [  [sg.Frame("Html to show",  layout_advertise)] ]
window = sg.Window('Web', layout)
while True:
    event, values = window.read()

    advertise = window['Advertise'].Widget

    advertise.setHtml(html)

    if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
        break
window.close()

This does nothing...

Then I tried :

import PySimpleGUIQt as sg
from PySide2.QtWebEngineWidgets import QWebEngineView
from PySide2.QtWidgets import *

html '''
<canvas id="myCanvas" width="100" height="25"">
Not supported</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(10,10,5,0,2*Math.PI);
ctx.stroke();
</script>
'''

app = sg.QApplication([]) # cause yoy have to create app before the widget
advertise = QWebEngineView()
advertise.setHtml(html)
# these three are because the psgq module require its elements to have those properties 
advertise.ParentContainer = None
advertise.Type = 'multiline'
advertise.Key = 'Ads'

layout = [  [advertise] ]
sys.exit(app.exec_()) #because it says you have to close the other app
window = sg.Window('Web').Layout(layout).Finalize()
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
        break
window.close()
0 Answers
Related