我有一个以字符串表示的 SVG 图形
svg_string='<svg height="100" width="500"><ellipse cx="240" cy="50" rx="220" ry="30" style="fill:yellow" /><ellipse cx="220" cy="50" rx="190" ry="20" style="fill:white" /></svg>'
Run Code Online (Sandbox Code Playgroud)
我想在Python启动的窗口上显示由 表示的图形svg_string,它是2个椭圆。
其伪代码应该是这样的
import pygame
def display_svg_figure(screen, svg_string):
# Code that draws the rendered SVG string on
# the screen
pass
background_colour = (255, 255, 255)
(width, height) = (900, 900)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Display SVG')
screen.fill(background_colour)
pygame.display.flip()
svg_string='<svg height="100" width="500"><ellipse cx="240" cy="50" rx="220" ry="30" style="fill:yellow" /><ellipse cx="220" cy="50" rx="190" ry="20" style="fill:white" /></svg>'
display_svg_figure(screen, svg_string)
running = True
while …Run Code Online (Sandbox Code Playgroud) 在 Python3/QT5 应用程序中,我试图显示最初作为字符串构建的 SVG 图像。我需要操作这个 SVG 图像(例如改变它的颜色),所以我的字符串随着时间的推移而改变。这是一个最小的工作示例:
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtSvg import QSvgWidget
svg_str = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="300" height="300" viewBox="0 0 300 300" id="smile" version="1.1">
<path
style="fill:#ffaaaa"
d="M 150,0 A 150,150 0 0 0 0,150 150,150 0 0 0 150,300 150,150 0 0 0
300,150 150,150 0 0 0 150,0 Z M 72,65 A 21,29.5 0 0 1 93,94.33
21,29.5 0 0 1 72,124 21,29.5 0 0 1 51,94.33 21,29.5 0 0 1 …Run Code Online (Sandbox Code Playgroud)