[Python] How to correct my Widget code which was working before and now it displays empty...

Discussão em 'Python' iniciado por Stack, Junho 28, 2025.

  1. Stack

    Stack Membro Participativo

    The following code was working till yesterday but now it displays empty data Frame.

    from IPython.display import display, Markdown, clear_output,IFrame
    import pytesseract
    pytesseract.pytesseract.tesseract_cmd = r"Tesseract-OCR\tesseract.exe"
    # widget packages
    import cv2
    import ipywidgets as widgets
    button = widgets.Button(description='My Button')
    out = widgets.Output()
    list_img = []
    def fun_data(x):
    image = cv2.imread(list_img[x],0)
    thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
    data = pytesseract.image_to_string(thresh, lang='eng',config='--psm 6')
    data = "\n".join([ll.rstrip() for ll in data.splitlines() if ll.strip()])
    data = data.split('\n')
    return data
    def on_button_clicked(_):
    # "linking function with output"
    with out:
    import os
    import pandas as pd
    directory = f'C:\\Users\\{os.getlogin()}\\Downloads\\'
    file_names = os.listdir(directory)
    for file_name in file_names:
    if file_name.startswith("imagename"):
    list_img.append(directory + file_name)
    s = pd.Series(list_img)
    s = s.to_dict()
    new = ([fun_data(a) for a in s])
    t = pd.DataFrame(new).T
    #t.columns =['Name', 'Code', 'Age', 'Weight']
    print(t)
    # what happens when we press the button
    # linking button and function together using a button's method
    button.on_click(on_button_clicked)
    # displaying button and its output together
    widgets.VBox([button,out])


    It was supposed to display dataframe on button click but now it displays empty dataframe on button click. https://youtu.be/wGFcUjzKyM8

    At present it shows empty dataframe. [​IMG]

    Continue reading...

Compartilhe esta Página