> For the complete documentation index, see [llms.txt](https://hntech.gitbook.io/blueconda-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hntech.gitbook.io/blueconda-documentation/your-first-project-beginners/working-with-templates.md).

# Working with Templates

Templates essentially allow you to easily reuse boilerplate code.

{% hint style="info" %}
Boilerplate code refers to standard, reusable code that is necessary in many programs but does not change significantly between different implementations. It is often used to set up the basic structure of a program.
{% endhint %}

This may not have very frequent use cases for beginners, but they're useful in some niche applications like GUI building! For now, let's focus on their use in a simpler case.

Suppose I have a tkinter element for a button like this:

\
`button = tk.Button(root, text="Option 1")`\
`button.pack()`

If I wanted to repeat this many times, I could use copy and paste. But with the amount of stuff that goes in my clipboard, it will get lost! And, what if I want to use it in another file as well?\
This is where templates come in. They're small pieces of code that you can use over and over again. To make one, empty the code editor and enter your code you'd like to use and click "Save as Template".

<figure><img src="/files/2UaxkJWcF5kyJM84o018" alt=""><figcaption><p>Save as Template</p></figcaption></figure>

Now it will ask you for a name to save it with. Choose something to remember it by, such as "tkinter Button."

Now, no matter which script we're editing, we can click the "insert template" button and retrieve this little handy code snippet for our project.

<figure><img src="/files/lKaaNdfPoepnoitHL8Y2" alt=""><figcaption><p>Load Template button</p></figcaption></figure>

Clicking the button opens a GUI to select what template we'd like to open. The template is inserted wherever our caret (the text cursor) is.

I've left some .py files in there for you to test, all written by me with the exception of 2, them being:

* Random 4 Digit Pin Generator&#x20;
* QR Code Generator&#x20;
* Simple Word Processor
* Tkinter Snake Game (from GeeksforGeeks)

{% embed url="<https://www.geeksforgeeks.org/snake-game-using-tkinter-python/>" %}
Snake Game Link
{% endembed %}

* Countdown App&#x20;
* Block Jumper Game with Pygame (by ChatGPT)
* Rock Paper Scissors&#x20;
* Text based calculator&#x20;

These scripts can be useful for you to learn or check out some Python examples. You may have to install some dependent libraries though (See: [Working With Packages](/blueconda-documentation/advancing-on-experienced/working-with-packages.md)).

Back to the Template system! In case all these files are bothering you, You can simply hit "Delete all Templates" and have them sent to the Recycle bin.

<figure><img src="/files/gTLvicBY0jDWz09dAsxk" alt="" width="76"><figcaption><p>The Template GUI</p></figcaption></figure>

And we're done with templates! Lets move on to reviewing code.
