0% found this document useful (0 votes)
22 views6 pages

Week 8: Write A Python Application To Create Basic Calculator To Demonstrate

The document describes creating a basic registration form using Python GUI components like text boxes, buttons, combo boxes, check buttons, radio buttons and more. It includes code to create the form layout and assign functions to components.

Uploaded by

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

Week 8: Write A Python Application To Create Basic Calculator To Demonstrate

The document describes creating a basic registration form using Python GUI components like text boxes, buttons, combo boxes, check buttons, radio buttons and more. It includes code to create the form layout and assign functions to components.

Uploaded by

Y Harika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Week 8: Write a Python application to create basic calculator to demonstrate

following GUI components. i) Button ii) Text box iii) Text area
Program:
import tkinter
class MyGUI:
def __init__(self):
# Create the main window widget.
self.main_window = tkinter.Tk()
self.top_frame = tkinter.Frame(self.main_window)
self.mid1_frame = tkinter.Frame(self.main_window)
self.mid2_frame = tkinter.Frame(self.main_window)
self.bottom_frame = tkinter.Frame(self.main_window)
self.bottom2_frame = tkinter.Frame(self.main_window)
self.label1 = tkinter.Label(self.top_frame, text="Num1:")
self.label2 = tkinter.Label(self.mid1_frame, text="Num2:")
self.num1_entry = tkinter.Entry(self.top_frame,width=10)
self.num2_entry = tkinter.Entry(self.mid1_frame,width=10)
self.add_button =
tkinter.Button(self.mid2_frame,text='+',command=self.add)
self.sub_button=tkinter.Button(self.mid2_frame,text='-
',command=self.sub)
self.mul_button =
tkinter.Button(self.mid2_frame,text='*',command=self.mul)

self.div_button=tkinter.Button(self.mid2_frame,text='/',command=self.div)
self.descr_label = tkinter.Label(self.bottom_frame,text = "Result:")
self.value=tkinter.StringVar()
self.result_label = tkinter.Label(self.bottom_frame,textvariable =
self.value)

self.quit_button=tkinter.Button(self.bottom2_frame,text='Quit',command=self
.main_window.destroy)
self.top_frame.pack()
self.mid1_frame.pack()
self.mid2_frame.pack()
self.bottom_frame.pack()
self.bottom2_frame.pack()
self.label1.pack(side='left')
self.label2.pack(side='left')
self.num1_entry.pack(side='right')
self.num2_entry.pack(side='right')
self.add_button.pack(side='left')
self.sub_button.pack(side='left')
self.mul_button.pack(side='left')
self.div_button.pack(side='left')
self.descr_label.pack(side='left')
self.result_label.pack(side='left')
self.quit_button.pack(side='left')
# Enter the tkinter main loop.
tkinter.mainloop()
def add(self):
a=float(self.num1_entry.get())
b=float(self.num2_entry.get())
c=a+b
self.value.set(c)
def sub(self):
a=float(self.num1_entry.get())
b=float(self.num2_entry.get())
c=a-b
self.value.set(c)
def mul(self):
a=float(self.num1_entry.get())
b=float(self.num2_entry.get())
c=a*b
self.value.set(c)
def div(self):
a=float(self.num1_entry.get())
b=float(self.num2_entry.get())
c=a/b
self.value.set(c)
# Create an instance of the MyGUI class.
my_gui = MyGUI()
Output:
Week 9: Write a Python application to create basic Registration form to
demonstrate following GUI components. i) Text box ii) Button iii) Submit
button iv) Combo box v) Check button vi) Text widget vii) Radio button
viii)Scrolled Text
Program:
import tkinter
class Reg:
def __init__(self):
self.base_window = tkinter.Tk()
self.base_window.geometry("500x500")
self.base_window.title("Registration form")
self.lb1= tkinter.Label(self.base_window, text="Enter Name", width=10,
font=("arial",12))
self.lb1.place(x=20, y=120)
self.en1= tkinter.Entry(self.base_window)
self.en1.place(x=200, y=120)
self.lb3= tkinter.Label(self.base_window, text="Enter Email", width=10,
font=("arial",12))
self.lb3.place(x=19, y=160)
self.en3= tkinter.Entry(self.base_window)
self.en3.place(x=200, y=160)
self.lb4= tkinter.Label(self.base_window, text="Contact Number",
width=13,font=("arial",12))
self.lb4.place(x=19, y=200)
self.en4=tkinter.Entry(self.base_window)
self.en4.place(x=200, y=200)
self.lb5= tkinter.Label(self.base_window, text="Select Gender", width=15,
font=("arial",12))
self.lb5.place(x=5, y=240)
vars = tkinter.IntVar()
tkinter.Radiobutton(self.base_window, text="Male",
padx=5,variable=vars, value=1).place(x=180,y=240)
tkinter.Radiobutton(self.base_window, text="Female", padx
=10,variable=vars,value=2).place(x=240,y=240)
self.lb2= tkinter.Label(self.base_window, text="Select Country",
width=13,font=("arial",12))
self.lb2.place(x=14,y=280)
list_of_cntry = ("United States", "India", "Nepal", "Germany")
cv = tkinter.StringVar()
self.drplist= tkinter.OptionMenu(self.base_window, cv, *list_of_cntry)
self.drplist.config(width=15)
cv.set("United States")
self.drplist.place(x=200, y=275)
self.lb6= tkinter.Label(self.base_window, text="Enter Password",
width=13,font=("arial",12))
self.lb6.place(x=19, y=320)
self.en6= tkinter.Entry(self.base_window, show='*')
self.en6.place(x=200, y=320)
tkinter.Button(self.base_window, text="Register",
width=10).place(x=200,y=400)
tkinter.mainloop()
#Creating the object
reg_form = Reg()
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy