0

我正在尝试使用 wx.html2 放置图像背景我已经尝试了所有的 css / html 标签,但图像不会进入。我想我用错了。我制作了一个 html 文档并对其进行了测试。它将在浏览器中正常工作。问题是什么?在html2中,图片相关的css似乎不是全部。

例如,与图像相关的东西,如渐变。

#-*- coding: utf-8 -*-
import wx.html2

HTML_CODE= """
<!DOCTYPE HTML>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <title>HTML TEST</title>
    <style type="text/css">
      body{{
        background-image: url(1.png);
      }} 
      table{{
        width: 100%;
        border-collapse: collapse      
      }}
      table, caption, th, td{{
        border: 1px solid black;
        text-align: center;   
        color:black;    
        height: 100px;
        font-size: 20px;           
      }}
    </style>
  </head>
  <body scroll='no'>
    <table>
      <caption>Hello world</caption>
      <thead>
        <tr>      
          <th>Ipsum</th>
          <th>Ipsum</th>
          <th>Ipsum</th>
          <th>Ipsum</th>
          <th>Ipsum</th>
          <th>Ipsum</th>  
        </tr>
      </thead>
      <tbody>
        <tr>       
          <td>{0}</td>
          <td>{1}</td>
          <td>{2}</td>     
          <td><p style='color:{3}'>{4}</p></td>
          <td><p style='color:{5}'>{6}</p></td>
          <td><p style='color:{7}'>{8}</p></td>      
        </tr>
        <tr>       
          <td>{9}</td>
          <td>{10}</td>
          <td>{11}</td>     
          <td><p style='color:{12}'>{13}</p></td>
          <td><p style='color:{14}'>{15}</p></td>
          <td><p style='color:{16}'>{17}</p></td>      
        </tr>
      </tbody>
      <tfoot>
        <tr>
          <td colspan="6">Table Foot</td>
        </tr>
      </tfoot>  
    </table> 
  </body>
</html>
"""
app = wx.App()
frame=wx.Frame(None,-1)
browser = wx.html2.WebView.New(frame, size=(460, 400))
browser.SetPage(HTML_CODE,"")
frame.Show(True)
app.MainLoop()

在此处输入图像描述

4

1 回答 1

1

You are using relative names for the image files, but the WebView does not know where to start when looking for that resource. You'll either need to specify the full pathname for the image resources, or you should pass a URL use use as the base location in the baseURL parameter of SetPage. It will probably need to be a file://... URL.

于 2017-08-30T17:21:30.953 回答