There is a code:

canvas = Canvas(root, width = 540, height = 540) canvas.place(x=0, y=0) img = ImageTk.PhotoImage(Image.open("C:\popka.jpg")) canvas.create_image(0,0, anchor=NW, image=img) 

Which makes the background image. It would be more convenient for me to directly indicate a link to a photo from a site, for example http://mypage.com/popka.jpg How to do this without crutches and as concisely as possible?

1 answer 1

Use the urlib library to use the link to your image.

 from PIL import Image, ImageTk from urllib.request import urlopen import tkinter as tk class Main(tk.Tk): def __init__(self): super().__init__() self.canvas = tk.Canvas(self, width=540, height=540) self.canvas.place(x=0, y=0) self.name_file = "https://pp.userapi.com/c614930/v614930016/9ae5/GYv6dLqMD7w.jpg?ava=1" self.img = ImageTk.PhotoImage(Image.open(urlopen(self.name_file))) self.canvas.create_image(0, 0, anchor=tk.NW, image=self.img) if __name__ == "__main__": Main().mainloop() 
  • thanks, we will test! - babyborn