create image tkinter set active background

Solutions on MaxInterview for create image tkinter set active background by the best coders in the world

showing results for - "create image tkinter set active background"
Golda
02 Sep 2020
1import tkinter as tk
2from PIL import ImageTk, Image
3
4class CanvasButton:
5    def __init__(self, canvas):
6        self.canvas = canvas
7        self.number = tk.IntVar()
8        self.button = tk.Button(canvas, textvariable=self.number,
9                                command=self.buttonclicked)
10        self.id = canvas.create_window(50, 100, width=25, height=25,
11                                       window=self.button)
12    def buttonclicked(self):
13        self.number.set(self.number.get()+1)  # auto updates Button
14
15root = tk.Tk()
16root.resizable(width=False, height=False)
17root.wm_attributes("-topmost", 1)
18
19imgpath = 'archipelago_big.gif'
20img = Image.open(imgpath)
21photo = ImageTk.PhotoImage(img)
22
23canvas = tk.Canvas(root, bd=0, highlightthickness=0)
24canvas.pack()
25canvas.create_image(0, 0, image=photo)
26
27CanvasButton(canvas)  # create a clickable button on the canvas
28
29root.mainloop()
30