PyCairo - How to Create Context Object Last Updated : 23 Jan, 2022 Comments Improve Suggest changes Like Article Like Report In this article we will see how we can create context object in pycairo python. Pycairo is a Python module providing bindings for the cairo graphics library. This library is used for creating SVG i.e vector files in python. The easiest and quickest way to open an SVG file to view it (read only) is with a modern web browser like Chrome, Firefox, Edge, or Internet Explorer—nearly all of them should provide some sort of rendering support for the SVG format. Context is the main object used when drawing with cairo. To draw with cairo, you create a Context, set the target surface, and drawing options for the Context, create shapes with functions like context.set_source_rgba( ), context.set_line_width( ), context.set_dash( ), context.move_to( ), context.rectangle( ) or context.stroke( ). In order to this we will use Context method Syntax : cairo.Context(surface) Argument : It takes target surface for the context Return : It returns a newly allocated Context Python # importing pycairo import cairo # creating a SVG surface # here geekline is file name & 700, 700 is dimension with cairo.SVGSurface("geekline.svg", 700, 700) as surface: # creating a cairo context object for SVG surface # using Context method context = cairo.Context(surface) # setting color of the context context.set_source_rgba(0, 0, 0, 1) # setting of line width context.set_line_width(4) # setting of line pattern context.set_dash([1.0]) # move the context to x,y position context.move_to(40, 30) # creating a rectangle(square) context.rectangle(100, 100, 100, 100) # stroke out the color and width property context.stroke() # printing message when file is saved print("File Saved") Output : Comment More infoAdvertise with us Next Article PyCairo - How to Create Context Object A ayush12arora Follow Improve Article Tags : Python Python-PyCairo Practice Tags : python Similar Reads PyCairo - How to close the path? In this article we will learn how we can make our pen path close using PyCairo in python. Adds a line segment to the path from the current point to the beginning of the current sub-path. Note : As of cairo version 1.2.4 any call to close_path() will place an explicit MOVE_TO element into the path im 2 min read PyCairo - How we can copy path? In this article we will learn how we can copy path of object using PyCairo in python. Creates a copy of the current path and returns it to the user as a Path. PyCairo : Pycairo is a Python module providing bindings for the cairo graphics library.This library is used for creating SVG i.e vector files 2 min read PyCairo - How we can get fill extents ? In this article we will learn how we can get fill extents using PyCairo in python. Computes a bounding box in user coordinates covering the area that would be affected, (the âcoloredâ area), by a context.fill() operation given the current path and fill parameter. If the current path is empty, return 3 min read PyCairo - How we can get clip extents ? In this article, we will learn how we can get clip extents using PyCairo in python. This module computes a bounding box in user coordinates covering the area inside the current clip. The current clip masks out any changes to the surface. Pycairo is a Python module providing bindings for the cairo gr 2 min read PYGLET â On Context Lost Event In this article we will see how we can trigger on context lost event 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 a 2 min read Like