重量轻渲染HTML使用Python CSS [英] Light-weight renderer HTML with CSS in Python

查看:252
本文介绍了重量轻渲染HTML使用Python CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,也许我还没有提到的问题以及第一次。你所有的答案是有趣的,但其中大部分是几乎全功能的Web浏览器,我的任务就简单多了。

Sorry, perhaps I haven't described the problem well first time. All your answers are interesting, but most of them are almost full-featured web browsers, my task is much simpler.

我打算写用在Linux上使用GUI框架(我还没有选择一个)之一的GUI应用程序。我将在我的应用程序中使用的HTML渲染成我的应用程序框架文本的一些属性之一 - 不同的字体等,这些都存储在CSS。

I'm planning to write a GUI application using one of the available on linux GUI frameworks (I haven't yet chosen one). I shall use html in my application to render into one of my application frames text with some attributes — different fonts etc, which are stored in CSS.

中的HTML,由我的应用程序产生,所以唯一的任务就是渲染HTML / CSS串。是否有任何控件,它可以做的只是渲染而已 - 没有历史,没有书签,没有网址加载等?如果没有,我将使用那些你建议之一 - 这是确定 - 但我只是有兴趣,如果有只是一个HTML的渲染,没有任何额外的功能。

The HTML shall be generated by my application, so the only task is to render a HTML / CSS string. Is there any widget which can do only that render and nothing more — no history, no bookmarks, no URL-loading etc? If there isn't I shall use one of those you advised — it's ok — but I'm just interested if there is just an html-renderer without any extra features.

推荐答案

您应使用的UI框架:

  • Qt: The simplest class to use would be QWebView
  • Gtk: pywebkitgtk would be the best answer, but you can find others in the PyGTK page.
  • In Tk is the TkHtml widget from here

这是另一种选择是通过像这样打开操作系统的默认浏览器:

An other option is to open the OS default web browser through something like this:

import webbrowser
url = 'http://www.python.org'

# Open URL in a new tab, if a browser window is already open.
webbrowser.open_new_tab(url + '/doc')

# Open URL in new window, raising the window if possible.
webbrowser.open_new(url)

您可以在这里找到对web浏览器模块更多信息。我认为,最简单的方法是,如果你正在寻找的东西非常轻量级的使用操作系统的浏览器,因为它不依赖于一个框架,它会在所有的平台上工作。使用Tk的可能是一种光的其他选项,不需要安装第三方框架。

You can find more info about the webbrowser module here. I think that the simplest way would be to use the os browser if you are looking for something very light-weight since it does not depend on a framework and it would work in all platforms. Using Tk may be an other option that is light and will not require to install a 3rd party framework.

这篇关于重量轻渲染HTML使用Python CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆