How To Create GUI In Python

It is very easy to create GUI in Python as compared to other programming languages. 
 
We can create a GUI in IDLE (python 3.5) and Visual Studio 2015 using python programming language
 
First, we know how to create GUI in IDLE(python 3.5) step by step
 
Step 1: Open IDLE (python 3.5) (shown in picture),
 
 

After opening IDLE, window form is open (show in picture below),
 
 
Click on "FILE" or (ctrl+N) to open new file for writing source code. (shown in picture below),
 
 
Now, editor is open and ready to use (shown in picture),
 
  
Step 2:
 
In python we create GUI using tkinter module, tkinter has some functions  for creating GUI and setting properties of our windows form.
  
So we import tkinter module in our program. (shown in picture),
 
from tkinter import* 
 
 
Now all functions of tkinter are imported and ready to use. Firstly we are creating an instance of tkinter.
 
obj=Tk()  #creating instance of tkinter
 
Now instance is created and gives title and dimensions to our windows form. 
  1. obj.title("c# corner") # set title of our window form  
  2. obj.geometry("300x300")  #set dimension of form   
Inserting text into our window form
  1. wintext = Text(obj)  
  2. wintext.insert(INSERT, "Hello.....")  
  3. wintext.insert(END, "welcome to c# corner.....")   
Now bind our text to window form and call mainloop.
  1. wintext.pack()  
  2. obj.mainloop()   
Finally our window form is created and our source code is, 
  1. from tkinter import*  
  2. obj=Tk()  
  3. obj.title("c# corner")  
  4. obj.geometry("300x300")  
  5. wintext = Text(obj)  
  6. wintext.insert(INSERT, "Hello.....")  
  7. wintext.insert(END, "welcome to c# corner.....")  
  8. wintext.pack()  
  9. obj.mainloop()  
  10.    
run our application (press F5) or click on run->run module.
 
 

Creating GUI in visual studio 2015 using python
 
Step 1:  Creating new project of python in visual studio (shown in picture below),
 
 
Write same code (shown in picture below), 
  1. from tkinter import*  
  2. obj=Tk()  
  3. obj.title("c# corner")  
  4. obj.geometry("300x300")  
  5. wintext = Text(obj)  
  6. wintext.insert(INSERT, "Hello.....")  
  7. wintext.insert(END, "welcome to c# corner.....")  
  8. wintext.pack()  
  9. obj.mainloop()   
 
Debug and start our application (shown in picture below), 
 
 
Our application (output):
 
 

Read more articles on Python:

Up Next
    Ebook Download
    View all
    Python
    Read by 0 people
    Download Now!
    Learn
    View all