def func(thread_number=[0]):
global thr, pole_can, img, filesi, img_2, i, p, filesi, i2, i5, a_flag, text_vidget, img_1, a_flag_text, text_vidget1, width_umnosh, height_umnosh, b, root1, text, img_list, img_list_vidget
local_thread_number = thread_number[0]
thread_number[0] += 1
def close():
thr = None
root1.destroy()
#создание окна
root1 = Toplevel(root)
root1.state('zoomed')
text_vidget1 = scrolledtext.ScrolledText(root1, width = 200, height = 100, state=DISABLED )
text_vidget1.pack()
close_btn = Button(root1, text="Close", state=DISABLED, command=close)
close_btn.pack()
for i in range(0,len(files)-1):
filesi = files[i]
stream = open(filesi,"rb")
bytes = bytearray(stream.read())
numpyarray = numpy.asarray(bytes, dtype=numpy.uint8)
bgrImage = cv2.imdecode(numpyarray, cv2.IMREAD_UNCHANGED)
height, width = bgrImage.shape[:2]
bgrImage = cv2.resize(bgrImage, (3500, 1700), interpolation = cv2.INTER_CUBIC)
img_gray = cv2.cvtColor(bgrImage, cv2.COLOR_BGR2GRAY)
a_img = cv2.medianBlur(img_gray, 5)
kernel = numpy.ones((5,5), numpy.uint8)
coords = numpy.column_stack(numpy.where(a_img > 0))
angle = cv2.minAreaRect(coords)[-1]
if angle < -45:
angle = -(90 + angle)
else:
angle = -angle
(h, w) = a_img.shape[:2]
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, angle, 1.0)
a_img = cv2.warpAffine(a_img, M, (w, h), flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE)
filename_img = "{}.png".format(os.getpid())
cv2.imwrite(filename_img, a_img)
pytesseract.pytesseract.tesseract_cmd ="C:/Program Files/Tesseract-OCR/tesseract.exe"
text = pytesseract.image_to_string(Image.open(filename_img),lang= "rus")
os.remove(filename_img)
text_vidget = scrolledtext.ScrolledText(root1, width = 50, height = 40)
text_vidget1.window_create(INSERT, window=text_vidget)
text_vidget.insert(1.0,text)
img_1 = ImageTk.PhotoImage(Image.open(filesi))
img_list.append(img_1)
insert = text_vidget1.image_create(INSERT, image =img_list[-1])
text_vidget.bind('<Control-a>', videlit)
text_vidget.bind('<Control-c>', copy)
text_vidget.bind('<Control-v>', vstavit)
b+=1
time.sleep(0.05)