多行文本无法显示在视图中
Multiple line text unable to show in view
我正在制作一个 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
我该如何修复这个错误?
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')
…
另请阅读 Tips section in the SimpleGUICS2Pygame 文档。
我正在制作一个 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
我该如何修复这个错误?
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')
…
另请阅读 Tips section in the SimpleGUICS2Pygame 文档。