Friday, November 5, 2021

 Chapter -15 (Graphical interface of Python)


Example-1:

Code:

from tkinter import *


def Calculate():

    temp=int(entry.get())

    temp=9/5*temp+32

    output_label.configure(text='Converted: {:.1f}'.format(temp))

    entry.delete(0,END)


root=Tk()

message_label=Label(text='Enter a temperature',font=('Verdana',16))

output_label=Label(font=('Verdana',16))

entry=Entry(font=('Verdana',16), width=4)

cal_button=Button(text='Ok' , font=('Verdana',16), command=Calculate)


message_label.grid(row=0, column=0)

entry.grid(row=0, column=1)

output_label.grid(row=1 , column=0 , columnspan=3)

cal_button.grid(row=0 , column=2)

mainloop()


Result:


Explanation:-


Example-2:-


Code:

from tkinter import *
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def callback(x):
    label.configure(text='Button {} clicked'.format(alphabet[x]))
    
root = Tk()
label=Label()
label.grid(row=1, column=0 , columnspan=26)

buttons = [0]*26
for i in range(26):
    buttons = Button(text=alphabet[i] , command=lambda x=i: callback(x))
    buttons.grid(row=0, column=i)
    
mainloop()


Result:


Explanation:-


Example-3:


Code:

from tkinter import *

def click():
    label.configure(text='Button clicked')

root=Tk()
button=Button(text='Click me', command=click)
label=Label(text='Button clicked')

label.grid(row=0 , column=0)
button.grid(row=1, column=0)

mainloop()

Result:


Explanation:-


Example-4: 

Code:


Result:

Explanation:-


How and Why you should learn python? About Python Programming Language Python is the programming language. By the help of Python you can ...