Python Program to Design GUI Applications Using OOPS

Python course with 57 real-time projects - Learn Python

Program 1

from tkinter import *
class Myclass:
    def __init__(self,myroot):
       self.mf=Frame(myroot,width=500,height=500,bg='yellow',cursor='cross')
       self.mf.pack()
       self.mf.propagate(0)
       self.btn1=Button(self.mf,width=7,height=2,text="Red",bg='red',font=('Arial,10,bold'),command=lambda :self.myclick(1))
       self.btn2 = Button(self.mf, width=7, height=2, text="Blue", bg='blue', font=('Arial,10,bold'),command=lambda :self.myclick(2))
       self.btn3 = Button(self.mf, width=7, height=2, text="Green", bg='green', font=('Arial,10,bold'),command=lambda :self.myclick(3))
       self.btn1.pack()
       self.btn2.pack()
       self.btn3.pack()

    def myclick(self,n):
       if(n==1):
        self.mf['bg']='red'
       elif(n==2):
           self.mf['bg']='blue'
       elif(n==3):
           self.mf['bg']='green'

#Calling
myroot=Tk()
myroot.geometry('500x500')
myroot.title("GUI OOPS Application")
myroot.wm_iconbitmap('2.ico')
myroot.maxsize(500,500)
myroot.minsize(500,500)
M1=Myclass(myroot)
myroot.mainloop()

 

Your opinion matters
Please write your valuable feedback about DataFlair on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *