0

Is there a Python (preferably 2.7) graphical module that allows me to display a web page (which I have in a .html file) in a pygame window?

I have a simple HTML file that I need to show and to scroll it.
The HTML code contains some CSS code but it certainly does not contains JavaScript or PHP code.

Once the HTML has been loaded and displayed, I need to be able of managing the events that occur in the HTML page (for example a button being clicked should be binded with some python functions in my code).

I don't need to call an external browser such as Mozilla Firefox or Chrome.

The question of which this questions has been marked as duplicate does not provide a full answer of this question.

Richard Wave
  • 89
  • 2
  • 10

1 Answers1

2

Pygame itself does not have support for HTML/CSS rendering. Instead either you have to parse it yourself, and add support that way.

Or use a supported toolkit such as PyQt Webview, pywebkitgtk or TkHtml. See here for some more options.


OK so I misunderstood your question.

So it looks like you are after this. So it looks like use html2text to get raw text. Also consider BeautifulSoup over this library since it is still being maintained. Example with BeautifulSoup:

from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
print soup.get_text()

Then use one of the methods here to create a widget in your Pygame window and add the raw text to it.

Also see the Pygame documentation on creating GUI.

As a side note, not using Pygame would make the task easier and using a traditional GUI toolkit like Tkinter/PyQt/WxPython/PyGtk since they all have methods of getting text.

Xantium
  • 11,201
  • 10
  • 62
  • 89
  • I've already tried those modules, but they are'n what i'm looking for. What I need is a simple module that parse and show the HTML code in my window, not an embedded browser – Richard Wave Jun 02 '18 at 17:39
  • @CariboniRiccardo So you just want raw text from a webpage. Minus styles and all? – Xantium Jun 02 '18 at 17:56
  • @CariboniRiccardo I've edited my answer. I hope this is what you are after. – Xantium Jun 02 '18 at 18:12
  • That is what i was looking for. I know, but i need pygame because of some functions that are not included in other GUI libraries – Richard Wave Jun 02 '18 at 18:42
  • 1
    @CariboniRiccardo OK, good luck with your project. I'll leave the first part of my question in case it is of any use in the future. – Xantium Jun 02 '18 at 18:45