[英]How to load HTML file with external link to CSS file with wxPython?
I'm trying to load an Html file with wx.html.HtmlWindow.我正在尝试使用 wx.html.HtmlWindow 加载一个 Html 文件。 The Html file is linked to an external style sheet (CSS) file. Html 文件链接到外部样式表 (CSS) 文件。 The problem is the Html window only shows the plain Html file without styling (colors, fonts, etc.) How can I solve this issue?问题是 Html 窗口只显示没有样式(颜色、字体等)的纯 Html 文件。我该如何解决这个问题?
HTML code: HTML代码:
<html>
<head>
<title>Embedded Style Sample</title>
<link href="E:\pythonGUI\styles.css" rel="stylesheet" type="text/css"/></head>
<body>
<h1>Embedded Style Sample testing</h1>
<h2>Next Line</h2>
</body>
</html>
CSS code: CSS代码:
h1{
color: #0000FF;
}
h2{
color: #00CCFF;
}
Python code:蟒蛇代码:
import wx
import wx.html
import wx.html2
class MyHtmlFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(
self,
parent,
-1,
title,
size = (600,400)
)
html = wx.html.HtmlWindow(self)
html.LoadPage("E:\\pythonGUI\\newtest.html")
app = wx.App()
frm = MyHtmlFrame(None, "Simple HTML File Viewer")
frm.Show()
app.MainLoop()
the Html file show on HTML window:在 HTML 窗口中显示的 Html 文件:
If you want complete HTML/CSS support as well as a Javascript engine, consider using wx.html2.WebView instead.如果您想要完整的 HTML/CSS 支持以及 Javascript 引擎,请考虑改用wx.html2.WebView 。
From wxpython docs:来自 wxpython 文档:
wx.html doesn't really have CSS support but it does support a few simple styles: you can use "text-align", "width", "vertical-align" and "background" with all elements and for SPAN elements a few other styles are additionally recognized: wx.html 并没有真正的 CSS 支持,但它确实支持一些简单的样式:您可以对所有元素使用“文本对齐”、“宽度”、“垂直对齐”和“背景”,对于 SPAN 元素,您可以使用一些其他样式也被识别:
color font-family font-size (only in point units) font-style (only “oblique”, “italic” and “normal” values are supported) font-weight (only “bold” and “normal” values are supported) text-decoration (only “underline” value is supported)
Using wx.html2.WebView instead of wx.html.HtmlWindow:使用 wx.html2.WebView 代替 wx.html.HtmlWindow:
import wx
import wx.html2
class About(wx.Frame):
def __init__(self):
wx.Panel.__init__(self,None,-1,title="Title",size=(700,700))
class Test(wx.Frame):
def __init__(self,title,pos,size):
wx.Frame.__init__(self,None,-1,title,pos,size)
self.tester=wx.html2.WebView.New(self)
self.tester.LoadURL("E:\\pythonGUI\\newtest.html")
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = Test("html2 web view", (20, 20), (800, 600))
frame.Show()
app.MainLoop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.