How to Run a Code in Python from Scratch

In this short post, I’ll show you how to run a code in Python from scratch.

To start, I’ll review the steps to run a Python code using a simple example. You’ll then be able to use the same steps to run any Python code.

Steps to Run a Code in Python from Scratch

Step 1: Download Python

If you haven’t already done so, download and then install Python:

Download Python

Step 2: Launch Python

Once the installation is completed, open the Python application:

Python 3.7

Then, open a new file (Tip: you can also open a new file by pressing Ctrl + N on your keyboard):

New File Python

A new screen would opened up, where you can copy/type your Python code:

Run a Code in Python from Scratch (Example Included)

Step 3: Copy your code

Copy your code into Python.

For illustration purposes, I created a simple program that will display ‘Hello World!’ in a small box.

You can try it out, by copying the code below into Python:

import tkinter as tk

root= tk.Tk()

canvas1 = tk.Canvas(root, width = 300, height = 300)
canvas1.pack()

label1 = tk.Label(root, text='Hello World!')
label1.config(font=('helvetica', 18),fg='teal')
canvas1.create_window(150, 150, window=label1)

root.mainloop()

Step 4: Run the code

Run the code in Python (Tip: you can press F5 to run the Python code):

How to Run a Code in Python from Scratch (Example Included)

You’ll be asked to save the source file:

How to Run a Code in Python from Scratch

Press OK and then choose the folder where you’d like to save the Python file. This is the result that you’ll get:

Hello World tkinter

As noted before, you can use the same steps to run any Python code of your choosing.