PYGLET – Accessing Index Line Property Last Updated : 12 May, 2021 Comments Improve Suggest changes Like Article Like Report In this article we will see how we can access index line property to the caret in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set to fill an entire screen (fullscreen). Caret is basically visible text insertion marker for pyglet.text.layout.IncrementalTextLayout. The caret is drawn as a single vertical bar at the document position on a text layout object. If mark is not None, it gives the unmoving end of the current text selection. Index line property refer to the index of the line caret is currently pointing at.We can create a window and caret with the help of commands given below # creating a window window = pyglet.window.Window(width, height, title) # creating a caret caret = pyglet.text.caret.Caret(layout, color=(255, 255, 255)) In order to create window we use line attribute with the caret objectSyntax : caret.lineArgument : It takes no argumentReturn : It returns integer Below is the implementation Python3 # importing pyglet module import pyglet import pyglet.window.key # width of window width = 500 # height of window height = 500 # caption i.e title of the window title = "Geeksforgeeks" # creating a window window = pyglet.window.Window(width, height, title) # text text = "Welcome to GeeksforGeeks Have a nice day" # batch object batch = pyglet.graphics.Batch() # creating document document = pyglet.text.document.FormattedDocument(text) # setting style to the document document.set_style(0, len(document.text), dict(font_name ='Arial', font_size = 16, color =(255, 255, 255, 255))) # creating a incremental text layout layout = pyglet.text.layout.IncrementalTextLayout(document, 400, 350, batch = batch) # creating a caret caret = pyglet.text.caret.Caret(layout, color =(150, 255, 150)) # caret to window push handlers window.push_handlers(caret) # setting caret style caret.set_style(dict(font_name ="Arial")) # on draw event @window.event def on_draw(): # clear the window window.clear() # draw the batch batch.draw() # caret to window push handlers window.push_handlers(caret) # key press event @window.event def on_key_press(symbol, modifier): # key "C" get press if symbol == pyglet.window.key.C: # closing the window # window.close() pass # image for icon img = image = pyglet.resource.image("logo.png") # setting image as icon window.set_icon(img) # getting current line index value = caret.line # printing the value print("Line Index: ", end ="") print(value) # caret.line = 10 # start running the application pyglet.app.run() Output : Line Index: 0 Create Quiz Comment R rakshitarora Follow 0 Improve R rakshitarora Follow 0 Improve Article Tags : Python Python-gui Python-Pyglet Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like