Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/python-image-button/main.py
5925 views
1
from tkinter import *
2
from tkinter import messagebox
3
4
5
def on_closing():
6
if messagebox.askokcancel("Выход из приложения", "Хотите выйти из приложения?"):
7
tk.destroy()
8
9
10
tk = Tk()
11
tk.protocol("WM_DELETE_WINDOW", on_closing)
12
tk.title("Мое приложение")
13
tk.resizable(0, 0)
14
tk.wm_attributes("-topmost", 1)
15
# tk.iconbitmap("bomb-3175208_640.ico")
16
17
canvas = Canvas(tk, width=600, height=600, highlightthickness=0)
18
canvas.pack()
19
20
21
def bg_color_red():
22
canvas.configure(bg="red")
23
id_button1.configure(bg="red", activebackground="red")
24
label.configure(bg="red", activebackground="red")
25
26
def bg_color_yellow(event):
27
canvas.configure(bg="yellow")
28
id_button1.configure(bg="yellow", activebackground="yellow")
29
label.configure(bg="yellow", activebackground="yellow")
30
31
our_button = PhotoImage(file="the-button-1692268_640.png")
32
our_button = our_button.subsample(2, 2)
33
# id_img1 = canvas.create_image(130,100, anchor="nw", image=our_button)
34
# Button(tk, image=our_button, highlightthickness=0, bd=0, command=lambda: print("Clicked!")).place(x=130, y=100)
35
#Button(tk, image=our_button, highlightthickness=0, bd=0, command=bg_color_red).place(x=130, y=100)
36
id_button1 = Button(tk, image=our_button, highlightthickness=0, bd=0, command=bg_color_red)
37
id_button1.place(x=130, y=100)
38
39
label = Label(tk, image=our_button)
40
label.place(x=130, y=300)
41
#label.bind("<Button-1>", lambda event: print("Click is OK!"))
42
label.bind("<Button-1>", bg_color_yellow)
43
label.bind("<Enter>", lambda event: label.place(x=132, y=302))
44
label.bind("<Leave>", lambda event: label.place(x=130, y=300))
45
46
47
tk.mainloop()
48
49