【发布时间】:2021-01-20 06:25:28
【问题描述】:
大家早上好/晚上好,我正在尝试使用 Tkinter 创建 GUI,并在单击 Tkinter 按钮后使用 PyQt5.QtWebEngineWidgets 显示 HTML 页面。一切正常,但关闭 PyQt HTML 页面并再次单击按钮后 - 一切都冻结并且内核正在重新启动。
我把最重要的代码贴在下面:
import tkinter as tk
window = tk.Tk()
btn = tk.Button(window, text = "Click me!", command = display_HTML)
btn.place(relx=0.2, rely=0.6, anchor="center")
window.mainloop()
和display_HTML函数:
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
import sys
def display_HTML():
app = QApplication(sys.argv)
br = QWebEngineView()
file_path = r"C:\....html"
local_url = QUrl.fromLocalFile(file_path)
br.load(local_url)
br.setWindowTitle("HTML content")
br.show()
app.exec_()
您能帮我解决这个问题吗?非常感谢。
【问题讨论】:
-
也许尝试创建另一种 QApplication 方式?
标签: python html button pyqt5 display