I am new on Python and I'm working on a project. When I work on GUI, I meet some difficulties.
I need to read a html file and put it on tkinter window. I have been looking for some solutions and someone recommanded tkinterhtml. I copied his example code, but something was wrong with the result. I do not know how to solve the problem. I would appreciate it if someone can help me.
from urllib.request import urlopen
from tkinter import *
import tkinterhtml as th
a = urlopen("https://www.baidu.com/?tn=78040160_14_pg&ch=8")
r = a.read()
d = r.decode()
root = Tk()
html = th.HtmlFrame(root)
html.pack()
html.set_content(d)
mainloop()
And the result is:
Process finished with exit code -1073741819 (0xC0000005)
This seems to be a problem with your python installation. Try reinstalling python, as it works fine for me:
Also, assuming you want to render HTML, which hasn't worked in the screenshot, I don't reccomend tkinterhtml - it doesn't work very well. PyQt will work a lot better for what you want if you don't mind using it. Install PyQt5 and PyQtWebEngine with pip:
pip install PyQt5
pip install PyQtWebEngine
and then try this example code for what you want:
import sys
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
web = QWebEngineView()
web.load(QUrl("https://www.baidu.com/?tn=78040160_14_pg&ch=8"))
web.show()
sys.exit(app.exec_())
User contributions licensed under CC BY-SA 3.0