import sys from tkinter import * from PIL import Image, ImageTk from threading import Thread def ui(): myPic = None def openimg(): global myPic img = Image.open("img.png") myPic = ImageTk.PhotoImage(img) return myPic def closeWindow(): sys.exit() tk = Tk() canvas = Canvas(tk, width=500, height=500) canvas.create_image(0, 0, image=openimg(), anchor="nw") canvas.pack(fill=BOTH, expand=True) # 自主处理关闭 x 按钮 tk.protocol('WM_DELETE_WINDOW', closeWindow) tk.mainloop() try: T = Thread(target=ui) T.start() except: print(1111) pass for i in range(10000000000): print(i)
标签:canvas,myPic,tkinter,img,完美,线程,tk,import From: https://www.cnblogs.com/zwnsyw/p/17360091.html