1

I'm making a python project and I needed to print the rules on the screen. I'm using the simplegui module and here is what I have.

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')

It gave me the error:

ValueError: text may not contain non-printing characters

How could I fix this bug?

Justsoft
  • 162
  • 4
  • 17
  • Do you know which characters are the problem? Does it work with a single line of text? Have you looked at `repr(text)` to check for any unexpected characters? – jonrsharpe Nov 20 '15 at 11:36
  • Yes, it works with one line of text. I can't see any weird characters. /n isn't the problem right? – Justsoft Nov 21 '15 at 07:10
  • I'd be inclined to try `text = "\n"` and find out! It's possible you'll have to position each line separately. – jonrsharpe Nov 21 '15 at 08:32

1 Answers1

0

The draw_text() function can not draw multiline. You must draw line by line.

But… I writed a function to draw multiline: draw_text_multi() You must import the simplegui_lib_draw module, because it is not a function of 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')
    …

Read also the Tips section in the SimpleGUICS2Pygame documentation.

Olivier Pirson
  • 737
  • 1
  • 5
  • 24