Answer to Question #99901 in Python for Kenzie Bryant

Question #99901
Edhesive 5.6
Use the starter code to create a program with 4 buttons and emoticons. Each button will make the graphical interface Display a different emoticon.
1
Expert's answer
2019-12-06T14:21:07-0500
from tkinter import *
from PIL import ImageTk, Image
 
root = Tk()
root.geometry('450x330')
 
canvas = Canvas(root,width=800,height=600)
canvas.pack()
    
 
def load_image(name):
    img = Image.open(name)
    img.thumbnail((200, 200), Image.ANTIALIAS)
    return ImageTk.PhotoImage(img)
 
def set_image(image):
    canvas.delete("all")
    canvas.create_image(100,115,image=image)
 
image = load_image("magas.png")
image2 = load_image("magas2.png")
 
set_image(image)
 
def naz():
    t1['text'] = "Город Назрань был основан..."
    set_image(image2)
 
def mag():
    t1['text'] = "Город Магас был основан..."
    set_image(image)
 
def kar():
    t1['text'] = "Город Карабулак был основан..."
    set_image(image2)
 
def mal():
    t1['text'] = "Город Малгобек был основан..."
    set_image(image)
 
t1 = Label(root)
t1.place(x=200, y=50)
 
t2 = Label(root, text="Описание 2")
t2.place(x=200, y=100)
 
t3 = Label(root, text="Описание 3")
t3.place(x=200, y=150)
 
btn1 = Button(root, text="Назрань", width=25, command=naz)
btn1.place(x=25, y=240)
 
btn2 = Button(root, text="Магас", width=25, command=mag)
btn2.place(x=240, y=240)
 
btn3 = Button(root, text="Карабулак", width=25, command=kar)
btn3.place(x=25, y=280)
 
btn4 = Button(root, text="Малгобек", width=25, command=mal)
btn4.place(x=240, y=280)
 
root.mainloop()

#https://ru.stackoverflow.com/questions/725168/%D0%9A%D0%B0%D0%BA-%D0%B2%D1%81%D1%82%D0%B0%D0%B2%D0%B8%D1%82%D1%8C-%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5-%D0%B2-%D0%BE%D0%BA%D0%BD%D0%BE-tkinter
# link to the ready solution

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS