Add comments to the code
Add comments to the code
import tkinter as tk
from PIL import ImageTk,Image
w = Tk()
w.title("North American Countries ")
w.configure(bg='#49A')
w.geometry('600x300')
f1 = LabelFrame(w, text="", width=100, highlightbackground='blue')
f1.grid(row=0, column=0, padx=20, pady=10, ipadx=20, ipady=10)
def fun1():
label1 = Label(w, text=" Ottawa ", padx=100, relief=RAISED)
label1.grid(row=2, column=1)
label2.configure(image=img1)
def fun2():
label1 = Label(w, text=" Washington, D.C ", padx=70, relief=RAISED)
label1.grid(row=2, column=1)
label2.configure(image=img2)
def fun3():
label1 = Label(w, text=" Mexico City ", padx=70, relief=RAISED)
label1.grid(row=2, column=1)
label2.configure(image=img3)
def fun4():
label1 = Label(w, text="", padx=70, relief=RAISED)
label1.grid(row=2, column=1)
label1 = Label(w, text="", padx=100, relief=RAISED)
label1.grid(row=2, column=1)
label2 = Label(w, text="", padx=100, relief=RAISED)
label2.grid(row=0, column=1)
imgurl1 = "/Users/Ali Computers/Desktop/canada.jpeg"
imgurl2 = "/Users/Ali Computers/Desktop/usa.jpeg"
imgurl3 = "/Users/Ali Computers/Desktop/mexico.jpeg"
img1 = ImageTk.PhotoImage(Image.open(imgurl1))
img2 = ImageTk.PhotoImage(Image.open(imgurl2))
img3 = ImageTk.PhotoImage(Image.open(imgurl3))
ca = Button(f1, text=" Canada ", width=20, command=fun1)
ca.grid(row=1, column=1)
us = Button(f1, text=" U.S.A ", width=20, command=fun2)
us.grid(row=2, column=1)
me = Button(f1, text=" Mexico ", width=20, command=fun3)
me.grid(row=3, column=1)
td = Button(w, text="Restore", width=20, command=fun4)
td.grid(row=5, column=1)
e = Button(w, text="Exit", command=exit, width=20)
e.grid(row=6, column=1)
w.mainloop()

Step by step
Solved in 4 steps with 2 images









