Create a simple Python GUI with IDLE GUI

tkinter is the python module which helps us to build the python GUI and it is ships together with the python package. In this article we will create a simple python GUI with the tkinter’s IDLE GUI. With just a few lines of code, we will create a button which when we click on it the GUI will be closed!

import tkinter as tk 
from tkinter import ttk 

win = tk.Tk() 
win.title("Python GUI") 

aLabel = ttk.Label(win, text="Click the button to close") 
aLabel.grid(column=0, row=0) 

def clickMe(): 
    exit(0) #close application

# Adding a Button 
action = ttk.Button(win, text="Click!", command=clickMe) 
action.grid(column=1, row=0) 

win.mainloop() #run the main loop

This is what we got…

Click the button to close the application
Click the button to close the application

We will move on by creating a real application on the next chapter…

Leave a Reply

Be the First to Comment!

avatar
  Subscribe  
Notify of