Separate threads, now cords more faster.

main
none 1 year ago
parent 77f0a2a19d
commit cc3bc15ac8

@ -7,45 +7,63 @@ import tkinter as tk
url = "https://pb.gulyaipole.fun/" url = "https://pb.gulyaipole.fun/"
root = tk.Tk() root = tk.Tk()
root.geometry("1280x720")
# Canvas for image
canvas = tk.Canvas(root) canvas = tk.Canvas(root)
canvas.pack() canvas.pack()
root.geometry("1280x720") # XY cords
ttext = tk.Canvas(root, width=90, height=20, bg="black") ttext = tk.Canvas(root, width=100, height=20, bg="black")
ttext.place(x=1180, y=0) ttext.place(x=1180, y=0)
text = ttext.create_text(40, 10, text="X: 1, Y: 1", fill="white") text = ttext.create_text(50, 10, text="X: 1, Y: 1", fill="white")
while True: # Run threads
x = root.winfo_pointerx() - root.winfo_rootx() from threading import Thread
y = 720 - (root.winfo_pointery() - root.winfo_rooty()) from time import sleep
ttext.itemconfig(text, text=f"X: {x}, Y: {y}")
# Открываем URL как файл def cords_up():
image_file = io.BytesIO(urllib.request.urlopen(url).read()) while True:
x = root.winfo_pointerx() - root.winfo_rootx()
y = 720 - (root.winfo_pointery() - root.winfo_rooty())
ttext.itemconfig(text, text=f"X: {x}, Y: {y}")
sleep(0.05)
# Открываем изображение в PIL cords = Thread(target=cords_up)
img = Image.open(image_file) cords.start()
# Преобразуем изображение в формат, поддерживаемый Tkinter def image_up():
tk_img = ImageTk.PhotoImage(img) global canvas_old, canvas
# Создаем новый Canvas для вывода изображения while True:
canvas = tk.Canvas(root, width=img.size[0], height=img.size[1]) # Prepare image for tkiner
canvas.create_image(0, 0, anchor="nw", image=tk_img) image_file = io.BytesIO(urllib.request.urlopen(url).read())
#canvas.pack() img = Image.open(image_file)
canvas.place(x=0, y=0) tk_img = ImageTk.PhotoImage(img)
try: # Create new canvas
canvas_old.destroy() canvas = tk.Canvas(root, width=img.size[0], height=img.size[1])
except: canvas.create_image(0, 0, anchor="nw", image=tk_img)
pass canvas.place(x=0, y=0)
try:
# New canvas and cords up
tk.Misc.lift(canvas)
tk.Misc.lift(ttext)
# Update
root.update()
sleep(2)
# Remove ols
canvas_old.destroy()
except:
pass
# New canvas now is old
canvas_old = canvas
image = Thread(target=image_up)
image.start()
canvas_old = canvas
tk.Misc.lift(ttext)
# Обновляем окно
root.update()
time.sleep(0.1)
root.mainloop() root.mainloop()
#

Loading…
Cancel
Save