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:
Step 2: Launch Python
Once the installation is completed, open the Python application:
Then, open a new file (Tip: you can also open a new file by pressing Ctrl + N on your keyboard):
A new screen would opened up, where you can copy/type your Python code:
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):
You’ll be asked to save the source file:
Press OK and then choose the folder where you’d like to save the Python file. This is the result that you’ll get:
As noted before, you can use the same steps to run any Python code of your choosing.