0% found this document useful (0 votes)
5 views3 pages

Python GUI Example

The document provides two examples of Python GUI applications using the Tkinter library. The first example creates a simple form for user input with labels and entry fields, while the second example calculates monthly payments and remaining loan balances based on user inputs. Both examples demonstrate the use of buttons and event handling in a Tkinter window.

Uploaded by

rajasekhar reddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Python GUI Example

The document provides two examples of Python GUI applications using the Tkinter library. The first example creates a simple form for user input with labels and entry fields, while the second example calculates monthly payments and remaining loan balances based on user inputs. Both examples demonstrate the use of buttons and event handling in a Tkinter window.

Uploaded by

rajasekhar reddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python GUI Example

Example1
from tkinter import *
from tkinter import ttk
window = Tk()
[Link]("Welcome to TutorialsPoint")
[Link]('400x400')
[Link](background = "grey");
a = Label(window ,text = "First Name").grid(row = 0,column = 0)
b = Label(window ,text = "Last Name").grid(row = 1,column = 0)
c = Label(window ,text = "Email Id").grid(row = 2,column = 0)
d = Label(window ,text = "Contact Number").grid(row = 3,column = 0)
a1 = Entry(window).grid(row = 0,column = 1)
b1 = Entry(window).grid(row = 1,column = 1)
c1 = Entry(window).grid(row = 2,column = 1)
d1 = Entry(window).grid(row = 3,column = 1)
def clicked():
res = "Welcome to " + [Link]()
[Link](text= res)
btn = [Link](window ,text="Submit").grid(row=4,column=0)
[Link]()

Example 2
from tkinter import *
fields = ('Annual Rate', 'Number of Payments', 'Loan Principle',
'Monthly Payment', 'Remaining Loan')
def monthly_payment(entries):
# period rate:
r = (float(entries['Annual Rate'].get()) / 100) / 12
print("r", r)
# principal loan:
loan = float(entries['Loan Principle'].get())
n = float(entries['Number of Payments'].get())
remaining_loan = float(entries['Remaining Loan'].get())
q = (1 + r)** n
monthly = r * ( (q * loan - remaining_loan) / ( q - 1 ))
monthly = ("%8.2f" % monthly).strip()
entries['Monthly Payment'].delete(0,END)
entries['Monthly Payment'].insert(0, monthly )
print("Monthly Payment: %f" % float(monthly))
def final_balance(entries):
# period rate:
r = (float(entries['Annual Rate'].get()) / 100) / 12
print("r", r)
# principal loan:
loan = float(entries['Loan Principle'].get())
n = float(entries['Number of Payments'].get())
q = (1 + r)** n
monthly = float(entries['Monthly Payment'].get())
q = (1 + r)** n
remaining = q * loan - ( (q - 1) / r) * monthly
remaining = ("%8.2f" % remaining).strip()
entries['Remaining Loan'].delete(0,END)
entries['Remaining Loan'].insert(0, remaining )
print("Remaining Loan: %f" % float(remaining))
def makeform(root, fields):
entries = {}
for field in fields:
row = Frame(root)
lab = Label(row, width=22, text=field+": ", anchor='w')
ent = Entry(row)
[Link](0,"0")
[Link](side = TOP, fill = X, padx = 5 , pady = 5)
[Link](side = LEFT)
[Link](side = RIGHT, expand = YES, fill = X)
entries[field] = ent
return entries
if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
[Link]('<Return>', (lambda event, e = ents: fetch(e)))
b1 = Button(root, text = 'Final Balance',
command=(lambda e = ents: final_balance(e)))
[Link](side = LEFT, padx = 5, pady = 5)
b2 = Button(root, text='Monthly Payment',
command=(lambda e = ents: monthly_payment(e)))
[Link](side = LEFT, padx = 5, pady = 5)
b3 = Button(root, text = 'Quit', command = [Link])
[Link](side = LEFT, padx = 5, pady = 5)
[Link]()

You might also like