0

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()
SkySibe
  • 153
  • 1
  • 7
  • So you aren't going to use `tkinter`? If so please remove the `tkinter` tag from the question. Also please provide a [mre] of what you tried. – TheLizzard Sep 11 '22 at 18:09
  • I mentioned the ```tkinter``` tag because the solution might include this module just like in the link I've added, and an example will be useless seemingly as my attempts only resulted with errors. – SkySibe Sep 11 '22 at 21:36
  • You have to show your best effort so that we can try and see where the error is coming from (include the error traceback in your question). Also it isn't a good idea to mix multiple GUI libraries because sometimes they interact with each other in unexpected ways. – TheLizzard Sep 11 '22 at 21:44
  • I just tried the PySimpleGui code with the PySimpleGuiQt libary, I'll try and post tomorrow. – SkySibe Sep 11 '22 at 21:55
  • 1
    There's no existing elements for HTML, you need know more about the structure of the PySimpleGUI layout and how to add the `QWebEngineView` into the layout after window finalized. The QWebEngineView class provides a widget that is used to view and edit web documents. – Jason Yang Sep 12 '22 at 03:24
  • It looks like it's impossible to add qt elements to the `psgq` layout – SkySibe Sep 12 '22 at 15:01

0 Answers0