[Python] How can I Display Widget button in PyCharm environment?

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

  1. Stack

    Stack Membro Participativo

    I try projects on jupyter notebook first and then try if they work on pycharm or not.Years back when I was doing https://www.youtube.com/watch?v=yaOaG-LI9kI project I remember the button displayed in my pycharm environment and worked as well.But now it shows [​IMG]

    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 button instead of VBox(children=(Button(description='Process Images',style=ButtonStyle()),Output()))

    Continue reading...

Compartilhe esta Página