Python tKinter 5

Button Click Example:

We have one lable and 5 buttons, as button is clicked a message is displayed in label.

 

# one label and 5 buttons
# on clicking a button message will be displayed in label
from tkinter import *
window = Tk()
#window properties

window.title("Welcome to TKinter Button Event Handling")
window.geometry('450x300')
window.configure(bg='blue')

#label properties
lbl = Label(window, text="Welcome To Python TKinter",font=("Arial Bold", 20))
lbl.place(x=10,y=40)

#functions required

def clicked_Amit():
    lbl.configure(text="Me Amit !!")
def clicked_Sumit():
    lbl.configure(text="Me Sumit !!")
def clicked_Kishan():
    lbl.configure(text="Me Kishan !!")
def clicked_Mohan():
    lbl.configure(text="Me Mohan !!")
def clicked_Clear():
    lbl.configure(text="Welcome To Python TKinter")

#buttons required
    
btn1 = Button(window, text="Amit", command=clicked_Amit)
btn1.place(x=10,y=150)

btn2 = Button(window, text="Sumit", command=clicked_Sumit)
btn2.place(x=70,y=150)

btn3 = Button(window, text="Kishan", command=clicked_Kishan)
btn3.place(x=130,y=150)

btn4 = Button(window, text="Mohan", command=clicked_Mohan)
btn4.place(x=200,y=150)

btn5 = Button(window, text="       Clear       ", command=clicked_Clear)
btn5.place(x=100,y=200)

window.mainloop()

Output:

When button “Kishan” is clicked:

 

Visitor Counter

0051039