1

我正在制作一个 python 项目,我需要在屏幕上打印规则。我正在使用 simplegui 模块,这就是我所拥有的。

text = """You will be given a number
    and a number of operations. The number
    on the top is the answer to the problem.
    You must fill the blanks with numbers that
    make the answer. Hit enter when you are 
    done, hit delete to go back."""
canvas.draw_text(text, (150, 250), 30, 'white')

它给了我错误:

ValueError: text may not contain non-printing characters

我怎样才能修复这个错误?

4

1 回答 1

0

draw_text()函数不能绘制多线。您必须逐行绘制。

但是……我写了一个绘制多线的函数: draw_text_multi() 你必须导入simplegui_lib_draw模块,因为它不是 CodeSkulptor 的函数。

try:
    import simplegui

    import user40_AeChfAkzlcqs3wG as simplegui_lib_draw
except ImportError:
    import SimpleGUICS2Pygame.simpleguics2pygame as simplegui

    import SimpleGUICS2Pygame.simplegui_lib as simplegui_lib_draw

def draw(canvas):
    …
    draw_text_multi(canvas,
                    """line 1
line 2
line 3""", (x, y), size, 'white', 'serif')
    …

另请阅读SimpleGUICS2Pygame文档中的提示部分。

于 2015-11-21T10:18:19.847 回答