arcade
arcade copied to clipboard
AssertionError: When the parameters 'multiline' and 'wrap_lines' are True, the parameter 'width' must be a number
Run this code:
import arcade
arcade.open_window(800, 600, 'Hello')
arcade.draw_text(text='Привет!', start_x=400, start_y=300, font_size=36, align='center')
arcade.run()
Getting error:
Traceback (most recent call last):
File "C:/draw_text.py", line 4, in <module>
arcade.draw_text(text='Привет!', start_x=400, start_y=300, font_size=36, align='center')
File "C:\Program Files\Python38\lib\site-packages\arcade\text_pyglet.py", line 138, in draw_text
label = pyglet.text.Label(
File "C:\Program Files\Python38\lib\site-packages\pyglet\text\__init__.py", line 447, in __init__
super(Label, self).__init__(document, x, y, width, height,
File "C:\Program Files\Python38\lib\site-packages\pyglet\text\__init__.py", line 268, in __init__
super(DocumentLabel, self).__init__(document,
File "C:\Program Files\Python38\lib\site-packages\pyglet\text\layout.py", line 889, in __init__
self._wrap_lines_invariant()
File "C:\Program Files\Python38\lib\site-packages\pyglet\text\layout.py", line 1155, in _wrap_lines_invariant
assert not self._wrap_lines or self._width, \
AssertionError: When the parameters 'multiline' and 'wrap_lines' are True, the parameter 'width' must be a number.
Process finished with exit code 1
Note: Works OK on Arcade 2.5.7 or if I remove align='center'
Python: 3.8 Arcade: 2.6.0 OS: Win 10
To align something, you need to add a width to align it against.
In this case an anchor is probably more in line with what you were wanting. Try adding anchor_x='center'
.
Hmm. Not sure if it's possible to make that compatible between versions.
The 2.5.7 API can get the width of the text and auto-center it based on that field width. The new 2.6 API does not have that ability. The width has to be specified.
I don't think there's an ability to get the width of the field?
There is label.content_width
for pyglet labels, but again, align and anchor are two different things here. Align is for aligning based on the width of the document (which is set with the width keyword argument), while anchor is changing where the x, y is based on the width of the label. Changing his code to anchor_x
anchors the text properly in the middle of the screen. If it was the reverse in the previous versions of Arcade, probably just need to change the align
argument to go into the anchor_x
parameter and vise versa.
With 3.0 breaking backward compatibility and arcade.draw_text
being discouraged. Should this issue be reviewed?
This is still a problem in 3.0. Caching this error dislaying something that makes more sense for an arcade user would be great.
The PR #2000 removes the interference of align with multiline. In this case it would no longer raise an Error.
It also checks if multiline is true and no width is given and gives a more clear error message.