pythonfreezecustomtkinter

TKINTER GUI not responding


As soon as I click the button with a command linked to a function, Tkinter GUI freezes and goes to not responding mode. I am not getting any error but also I am not getting any output.

        def SBPRM(self):

            premium_acc_data_path = r'' + self.entry_fields[0].get()
            tagging_data_path = r'' + self.entry_fields[1].get()
            desc_acc_data_path = r'' + self.entry_fields[4].get()
            hr_data_path = r'' + self.entry_fields[2].get()
            iibf_data_path = r'' + self.entry_fields[3].get()
            claw_back = int(self.entry_fields[5].get())

these files are pretty big and the almost 200 lines of codes after these which would manipulate the data and save it as a excel file in downloads. What should I do? so that these files will be read using pd.read and the data gets manipulated properly


Solution

  • Use thread for fix freeze. Big files slow GUI. Here example:

    import threading
    import tkinter as tk
    import pandas as pd
    
    def SBPRM():
        paths = [entry_fields[i].get() for i in range(6)]
        thread = threading.Thread(target=process_data, args=paths)
        thread.start()
    
    def process_data(*paths):
        premium_data = pd.read_csv(paths[0])
        tagging_data = pd.read_csv(paths[1])
        # Your long data processing code here
    
    # Tkinter setup code here
    

    This make GUI not freeze.