beginner lesson 1

Scripting with Krita

Overview of scripting in Krita. Go over the Scripter tool for writing and executing basic scripts

Isn't Krita a drawing program?

Welcome to the wonderful world of scripting Krita. Scripting allows you to add features and modify many many areas in the Krita application. These are some of the benefits of scripting vs. trying to be a hardcore Krita developer

  1. No need to setup a development environment. This means you don't have to download the entire krita source code, download and install everything the source needs, and figure out how to compile it.
  2. Avoid long compile times when you want to test out your code. Going from source code to a running Krita can sometimes take almost an hour. That is a long time to wait.
  3. Works equally well across all operating systems. This means you can run your scripts the same if you copy them between a Windows, Mac, or Linux operating system.
  4. It is very easy to share your scripts with other people online and have them try things out. For a hardcore Krita developer that uses C++, they have to make a special build of the entire application to try out changes.
  5. Uses Python which is better for newbies. This is a common language and not too hard to learn. If you were a hardcore Krita developer, you would have to learn C++, which has some pretty complicated concepts to learn like managing memory.

This all means that it is easy to get started without a lot of technical knowledge. Let's see where we will be doing all our work in.

Tip

There are some things scripting won't be able to do. With the help of the Krita community and Krita developers, new things are getting added all the time.

Overview of Scripter

Open Krita and there will be an option on the main menu Tools > Scripts > Scripter. A window will appear

Scripter Window

This is what we will refer to as “Scripter”. The top text area is where we will be writing code. The bottom area is where we can see the results and test things with the Output tab.

Change editor background color

If the top code part is white and you want to change the style like my image. This is done from the scripter main menu. From the Scripter menu, go to File > Settings. There is an area called “Syntax Style”. The one I am using is called BreezeDarkSyntaxStyle. The window will update immediately as you change styles. There is no save button to confirm. This setting will be remembered the next time you start Krita, so you shouldn't have to change it again.

Run your first script

In the top area type the following:

print("Hello World")

To run this, you need to press the play button in the toolbar. Press that and you should see the output like below.

Basic printing

The print() function will output something to the Output area. This will be used in the future a lot when we want to see how our script is behaving. The warning in the output is ok. It means that this script that we have is not saved anywhere. If we were to close Krita and open it later, we would lose our scripting.

Load and save scripts

You can load and save scripts from Scripter's main menu. There are a few options that you have available from the File menu in scripter.

  1. New - Wipes out your current file and starts a new one. If you previously had an open file, it unlinks it from that one.
  2. Open - Open a file from your computer.
  3. Reload File - This is the same as opening up your file again. You will lose any changes that you have not saved.
  4. Save - Saves a new file to your computer, or creates a new file to save.
  5. Save as - Opens up the save dialog so you can save the file as a new file.

When you are saving and loading files, the common file format that is used is a “py” file. When you save a script it might be called something like “my-custom-scripts.py”. The py extension is meant to communicate that this is a Python file.

Conclusion

In this lesson we learned a bit about why scripting is a good alternative for doing modifications to Krita. We also learned where to write scripts, how to customize the scripting window, run a script, and how to load and save script files.

Have questions, need help, or find a typo?

Head to the Krita artists where we have a dedicated area for plugin development and give any feedback you might have.

;