0

Every time I click a button in the app I am currently working on, the program goes to "no response" and then launches another instance of itself while the old one is still active. I don't know how or why because while having it run inside the IDE it works. As soon as I pack it with auto-py-to-exe, it does this.

The code for the Button:

info_but = customtkinter.CTkButton(menu,text="", font=custom_font,          
                                image=info_def,bg_color="#FDF6E4",fg_color="#FDF6E4",hover_color="#3b444b",
                                width=70, command= info_menu,height=70)
info_but.place(x=20, y=220)

The function getting called:

def info_menu():
    global update_label, gpu_label

    stop_thread()
    # Beispielverwendung
    os_ver = f"{uname().system} {uname().release}"  # get_gpu_models()

    threaded_check_for_new_version(repo_owner, repo_name, current_version)

    proc_info = cpuinfo.get_cpu_info()

    # RAM Informationen

    ram = psutil.virtual_memory()

    for child in frame.winfo_children():
        child.destroy()

    content_frame = customtkinter.CTkFrame(frame, width=880, height=600)
    content_frame.place(x=0, y=0)

    label = customtkinter.CTkLabel(content_frame, text=f"General Information:",anchor="w", justify="left", width=200, height=30, font=custom_font2)
    label.grid(row=0, column=0, padx=(10,10),pady=(10,30))

    label = customtkinter.CTkLabel(content_frame, text=f"App version:",anchor="w", width=130, justify="left", height=20,font=custom_font)
    label.grid(row=2, column=0, padx=(150,10),pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"{current_version}",anchor="w", width=130, height=20,font=custom_font)
    label.grid(row=2, column=1, padx=360,pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"Build date:",anchor="w", width=130, justify="left", height=20,font=custom_font)
    label.grid(row=3, column=0, padx=(150,10),pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"05/2024",anchor="w", width=130, height=20,font=custom_font)
    label.grid(row=3, column=1, padx=360,pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"Publisher:",anchor="w", width=130, justify="left", height=20,font=custom_font)
    label.grid(row=4, column=0, padx=(150,10),pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"",anchor="w", width=130, height=20,font=custom_font)
    label.grid(row=4, column=1, padx=360,pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"Update avaiable:",anchor="w", width=130, justify="left", height=20,font=custom_font)
    label.grid(row=5, column=0, padx=(150,10),pady=10)

    update_label = customtkinter.CTkLabel(content_frame, text=f"Working"
                                   ,anchor="w", width=130, height=20,font=custom_font)
    update_label.grid(row=5, column=1, padx=360,pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"Authentic:",anchor="w", width=130, justify="left", height=20,font=custom_font)
    label.grid(row=6, column=0, padx=(150,10),pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"Yes",anchor="w", width=130, height=30,font=custom_font)
    label.grid(row=6, column=1, padx=360,pady=10)


    label = customtkinter.CTkLabel(content_frame, text=f"System Information:",anchor="w", justify="left", width=200, height=30, font=custom_font2)
    label.grid(row=7, column=0, padx=(10,10),pady=(20,10))


    label = customtkinter.CTkLabel(content_frame, text=f"CPU Model:",anchor="w", width=130, justify="left", height=20,font=custom_font)
    label.grid(row=10, column=0, padx=(150,10),pady=10)


    label = customtkinter.CTkLabel(content_frame, text=f"{'{0}'.format(proc_info['brand_raw'])}",anchor="w", width=130, height=20,font=custom_font,wraplength=130)
    label.grid(row=10, column=1, padx=360,pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"Architecture:",anchor="w", width=130, justify="left", height=20,font=custom_font)
    label.grid(row=9, column=0, padx=(150,10),pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"{'{0}'.format(proc_info['arch'])}",anchor="w", width=130, height=20,font=custom_font)
    label.grid(row=9, column=1, padx=360,pady=10)


    label = customtkinter.CTkLabel(content_frame, text=f"OS:",anchor="w", width=130, justify="left", height=20,font=custom_font)
    label.grid(row=8, column=0, padx=(150,10),pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"{os_ver}",anchor="w", width=130, height=20,font=custom_font)
    label.grid(row=8, column=1, padx=360,pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"GPU:",anchor="w", width=130, justify="left", height=20,font=custom_font)
    label.grid(row=11, column=0, padx=(150,10),pady=10)

    gpu_label = customtkinter.CTkLabel(content_frame, text=f"Working",anchor="w", width=130, height=20,font=custom_font)
    gpu_label.grid(row=11, column=1, padx=360,pady=10)


    label = customtkinter.CTkLabel(content_frame, text=f"Avaiable RAM:",anchor="nw", width=130, justify="left", height=20,font=custom_font)
    label.grid(row=12, column=0, padx=(150,10),pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"{str(ram.total / 1024**3)[:4]} GB",anchor="w", width=130, height=20,font=custom_font)
    label.grid(row=12, column=1, padx=360,pady=(10,10))

    label = customtkinter.CTkLabel(content_frame, text=f"",anchor="nw", width=130, justify="left", height=20,font=custom_font)
    label.grid(row=13, column=0, padx=(150,10),pady=10)

    label = customtkinter.CTkLabel(content_frame, text=f"",anchor="w", width=130, height=20,font=custom_font)
    label.grid(row=13, column=1, padx=360,pady=(10,10))

    threaded_get_gpu_models(gpu_label)

affecting:

def fetch_latest_version(repo_owner, repo_name, current_version):
    global cached_result
    url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/releases/latest"
    response = requests.get(url)
    if response.status_code == 200:
        latest_version = response.json().get('tag_name')
        comparison_result = semver.compare(current_version, latest_version)
        if comparison_result < 0:
            cached_result = [True, latest_version]
        elif comparison_result == 0:
            cached_result = [False, latest_version]
        else:
            cached_result = [False, current_version]  # Deine Version ist neuer
    else:
        cached_result = [False, None]

    update_label_text()


def update_label_text():
    global cached_result, update_label
    if cached_result[0]:
        update_label.configure(text="Yes")
    else:
        if cached_result[1] is None:
            update_label.configure(text="Error")
        else:
            update_label.configure(text="No")
    root.update()


def check_for_new_version(repo_owner, repo_name, current_version):
    global cached_result, cache_lock
    root.update()
    with cache_lock:
        if cached_result[1] is None:
            fetch_latest_version(repo_owner, repo_name, current_version)
        else:
            update_label_text()


def threaded_check_for_new_version(repo_owner, repo_name, current_version):
    thread = threading.Thread(target=check_for_new_version, args=(repo_owner, repo_name, current_version))
    thread.start()


def fetch_gpu_models(result):
    try:
        gpus = GPUtil.getGPUs()
        gpu_models = set(gpu.name for gpu in gpus)
        result.append(list(gpu_models) if gpu_models else ["Unknown"])
    except Exception as e:
        result.append(["Unknown"])
    update_model_label(gpu_label,result[0])


def update_model_label(gpu_label,gpu_models):
    gpu_label.configure(text=f"{gpu_models[0]}")
    root.update()


def get_gpu_models(gpu_label):
    result = []
    fetch_gpu_models(result)
    return result[0] if result else ["Unknown"]


def threaded_get_gpu_models(gpu_label):
    thread = threading.Thread(target=get_gpu_models, args=(gpu_label,))
    thread.start()

I fixed all errors the IDE threw at me when I clicked the button like thread handling and such, but still no luck. I also changed the names of the variable and function because I noticed that I (stupid) used the name multiple times for different things..

stop_thread is NOT the culprit since it was added AFTER the error occured.

5
  • 1
    What is info_menu? Commented Jun 5, 2024 at 15:06
  • Info_menu is the function getting called upon the button click. It contains a lot of label definitions like content and coordinates. It also contains the function calls shown in the second code block :) Commented Jun 5, 2024 at 15:10
  • 2
    And you didn't think that might be relevant to answering your question? Commented Jun 5, 2024 at 15:14
  • I thought that the information that the info_menu just contains label placements is enough since I am quite confident that those are not at fault :( . I think that the problem must be at the functions in block 2 or 3 . This is the only "active" stuff happening in info_menu. I will try to add the function as an answer Commented Jun 5, 2024 at 15:24
  • 1
    I think you need to call multiprocessing.freeze_support() (need to import multiprocessing module). Commented Jun 6, 2024 at 3:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.