what is python gui code example

Example 1: python basic gui

from tkinter import *


# def click func
def click():
    # Getting the text info as an int() & Error handling
    try:
        text_info_1 = float(text1.get())
        text_info_2 = float(text2.get())
    except Exception as e:
        text1.delete(0, END)
        text2.delete(0, END)
        text3.delete(0, END)
        text3.insert(0, f'Error: {e}')
        return
    # actual part of the func
    text3.delete(0, END)
    text3.insert(0, text_info_1 + text_info_2)

# Gui Config
root = Tk()
root.geometry('300x400')
root.title('Poop')

# The actual gui
label1 = Label(root, text='Write something!')
label1.pack()

spacing1 = Label(root)
spacing1.pack()

text1 = Entry(root)
text1.pack(ipadx=20)

spacing2 = Label(root, text='+')
spacing2.pack()

text2 = Entry(root)
text2.pack(ipadx=20)

spacing3 = Label(root)
spacing3.pack()

button = Button(root, text='Click me!', command=click)
button.pack()

spacing4 = Label(root)
spacing4.pack()

text3 = Entry(root)
text3.pack(ipadx=60)

# Making the gui run
root.mainloop()

Example 2: what is python

# official Answer
Python is an interpreted, object-oriented, high-level programming 
language with dynamic semantics. Its high-level built in data 
structures, combined with dynamic typing and dynamic binding, 
make it very attractive for Rapid Application Development, as 
well as for use as a scripting or glue language to connect existing 
components together. 

# My answer
This interpreted language is one of the best thing that have happened 
since perl. Perl was my favorite at one time because of amazing 
community support. Python has made significant strides in that area.
Some time you code and wish if it was possible to do it this way. It 
is highly likely you'll find out someone already implemented that. The
tool pip is your best friend which makes importing libraries a 
cakewalk. You don't have to jump too many hoops to implment a feature.

Example 3: python gui

import tkinter as tk
#Importing the main module
window = tk.Tk()
window.mainloop()

Tags:

Misc Example