python – why does my window doesn’t work for on_draw?


I was watching a video about pyglet and I tried to create a triangle:

import pyglet
from pyglet.gl import *

class mywindow(pyglet.window.Window):
    def __init__(self, *args,**kwargs):
        super().__init__(*args,**kwargs)
        self.set_minimum_size(300,300)
        
window = mywindow(300,300,"deneme", True)

def on_draw():
    glBegin(GL_TRIANGLE)
    glColor3b(255,0,0)
    glVertex2f(-1,0)
    glColor3b(0,255,0)
    glVertex2f(1,0)
    glColor3b(0,0,255)
    glVertex2f(0,1)

window.on_draw()
pyglet.app.run()

    

when I run this code; I get this error:

AttributeError: 'mywindow' object has no attribute 'on_draw'

Any idea how to solve this?