TypeError: unsupported operand type

This is the program I'm writing that should display some text in a window ...

import pyglet
from pyglet import window
from pyglet.text.layout import TextLayout

class Window(pyglet.window.Window):
    def __init__(self):
        super(Window, self).__init__(width = 800, height = 600,
                                 caption = "Prototype")

        self.disclaimer = pyglet.text.Label("Hello World",
                                   font_name = 'Times New Roman',
                                   font_size=36,
                                   color = (255, 255, 255, 255),
                                   x = TextLayout.width / 2,
                                   y = TextLayout.height / 2,
                                   anchor_x='center', anchor_y='center')

def on_draw(self):
    self.clear()
    self.disclaimer.draw()

if __name__ == '__main__':
    window = Window()
    pyglet.app.run()

... however, every time I try to run it, I get this error

line 16
x = TextLayout.width / 2,
TypeError: unsupported operand type(s) for /: 'property' and 'int'

I'm sure this means that I tried to split the string, but the Pyglet documentation says that width and height are int. I have no idea what I'm doing wrong.

+3
source share
2 answers

TextLayout - class - TextLayout.width , ; width TextLayout, ! , , , ( ).

, :

                               x = self.width / 2,
                               y = self.height / 2,

, TextLayout.

+3

Python 3.x, / float. //, ( ).

0

Source: https://habr.com/ru/post/1751944/


All Articles