Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

html to image pygame python

'''
There's no way to do this directly in pygame. But you can use an external tool like wkhtmltoimage to render your HTML to an image and use that in pygame.
Here's a simple example using imgkit (a python wrapper for wkhtmltoimage):
'''

import pygame
import imgkit
from io import BytesIO

def main():
    config = imgkit.config(wkhtmltoimage=r'C:Program Fileswkhtmltopdfinwkhtmltoimage.exe')

    pygame.init()
    screen = pygame.display.set_mode((600, 480))

    html = "<style type = 'text/css'> body { font-family: 'Arial' } </style><body><h1>Html rendering</h1><div><ul><li><em>using pygame</em></li><li><strong>using imgkit</strong></li></ul></div></body>"
    img = imgkit.from_string(html, False, config=config)
    surface = pygame.image.load(BytesIO(img)).subsurface((0,0,280,123))
    r = 0
    center = screen.get_rect().center
    clock = pygame.time.Clock()
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT: 
                return

        screen.fill('white')
        tmp = pygame.transform.rotozoom(surface, r, 1)
        tmp_r = tmp.get_rect(center=center)
        screen.blit(tmp, tmp_r)
        r += 1
        pygame.display.flip()
        clock.tick(60)

if __name__ == '__main__':
    main()
    
    https://i.stack.imgur.com/JXSrx.gif
Comment

PREVIOUS NEXT
Code Example
Python :: change the Values to Numpy Array 
Python :: pie plot chance size python 
Python :: ascci value pyth 
Python :: encrypt 
Python :: kivy file chooser path selector 
Python :: region python 
Python :: input what is your name python 
Python :: prettytable in python 
Python :: how to save a from with createvue django 
Python :: rom requests_html import HTML 
Python :: forward fill in pyspark 
Python :: genrate requirments.txt pytohn 
Python :: django python get more commands paramaters 
Python :: the most effective search methods in python with example 
Python :: kite order syntax 
Python :: como colocar uma variavel no print python 
Python :: run python script from applescript 
Python :: pandas to csv if no already present 
Python :: python data manipulation_16.06.2022 
Python :: biopython parse fasta 
Python :: Horizontal concatication 
Python :: how to read file from terminal in python inside code 
Python :: change between two python 3 version in raspberrry pi 
Python :: the 100th iteration in python next() 
Python :: passport parsing python 
Python :: email grabber python 
Python :: why static kwyword not in python 
Python :: tuple parameter function python is None 
Python :: does building wheel for dlib setup py takes forever 
Python :: You will be passed a file path P and string S on the command line. Output the number of times the string S appears in the file P. 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =