How to Create GUI Applications with Python
Tags: python, programming
Published: 2021-05-07 13:12:18

[Python](https://python.org) started as primarily a command line language. That means that it is most typically used to write scripts to automate tasks or to perform some sequence of actions. 

GUI applications are an integral part of our daily lives. Yet, when most people are learning to program, they spend hours on making a working terminal program in Python.

How to start making GUI applications with Python? :snake:

You can create a GUI with a library. There are several libraries you can use. 


**PyQt** :rocket:

PyQt is the most popular Python bindings for Qt, a cross-platform GUI framework. It comes with many widgets and has a modern look and feel.  Some things made with it are the KDE desktop and related applications.

PyQt works on all operating systems including Windows, Mac OS X and Linux. It also comes with a [drag and drop designer](https://pythonbasics.org/qt-designer-python/) program.

If you are new to PyQt, I recommend [this course](https://gumroad.com/l/pysqtsamples)

![pyqt has a modern appearance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oplzg2yqgmnecqt82zc9.jpeg)

Hello World in PyQt looks like this:

```python
import sys

from PyQt5.QtWidgets import QApplication, QWidget

if __name__ == '__main__':
    app = QApplication(sys.argv)

    w = QWidget()
    w.resize(250, 150)
    w.move(300, 300)
    w.setWindowTitle('Simple')
    w.show()

    sys.exit(app.exec_())
```
source: [hello world](https://pythonpyqt.com/pyqt-hello-world/)

**tkinter** :smile:

You can use Tkinter as your GUI library. It is the most commonly used GUI library in Python. If you don't have Tkinter in your environment, you can install it either by adding Python's Tkinter package or by installing it from your distro's repository.

The limitations of tkinter is that it doesn't have many widgets available and it has quite an old fashioned look and feel.

Hello world in tkinter looks like this. To learn more about tkinter see [this article](https://python-commandments.org/tkinter-basics/)

```python
import tkinter as tk
top = tk.Tk()
top.title("Hello World")
labelHello = tk.Label(top, text = "Hello World! ")
labelHello.pack()
top.mainloop()
```

Tkinter has a traditional look (90s) and feel

![tkinter has a traditional look and feel](https://pythonspot.com/wp-content/uploads/2015/05/tkButton4.png.webp)

**pysimplegui**

Another option is PySimpleGUI. This lets you create very basic user interfaces using a layout. Underneath it uses PyQt, tkinter and remi so it's a good idea to learn those first. 

```python
import PySimpleGUI as sg                        # Part 1 - The import

# Define the window's contents
layout = [  [sg.Text("What's your name?")],     # Part 2 - The Layout
            [sg.Input()],
            [sg.Button('Ok')] ]

# Create the window
window = sg.Window('Window Title', layout)      # Part 3 - Window Defintion

# Display and interact with the Window
event, values = window.read()                   # Part 4 - Event loop or Window.read call

# Do something with the information gathered
print('Hello', values[0], "! Thanks for trying PySimpleGUI")

# Finish up by removing from the screen
window.close()     
```