简体   繁体   中英

Tkinter app crashes on MacOS after root.destroy() and calling filedialog.askdirectory() for the second time

created a tkinter app that works perfectly on Windows, however the app seems to crash on MacOS on a really specific moment.

Some context. The app functions as a GUI on an ODBC connection between local computers and the Data warehouse. After a successful upload/download the users can restart the app and go for another upload/download of data.

After a root.destroy() the app starts again and once the user selects the browse button again and the scripts calls file dialog.askdirectory() for the second time the app crashes and gives a segmentation fault 11.

EDIT: I included the error message from the segmentation fault below the code Does anyone know how to resolve this?

See relevant part of the script below (please do not mind the import list):

import os
import threading
import tkinter as tk
import importlib
import requests
from tkinter import filedialog
import databricks_odbc_tool 
from tkinter import *
from tkinter import ttk
from tkinter.filedialog import askopenfile
from databricks_odbc_tool import run_from_gui
from pathlib import Path
from os import path
from PIL import ImageTk, Image
import calendar
import time
import webbrowser
import sys
import promptlib
#----------------------------------INIT CLASS-------------------------------------------------------#

class App():
    
    gmt = time.gmtime()
    ts = calendar.timegm(gmt)
    function = 'upload'
    file_format = 'csv'
    filepath = Path.home()
    delimiter = '\t'
    delimiter_text = "Tab (\\t)"
    header_bool = 1
    replace = "true"
    query_text = '"'
    tq = '"'
    new_file_name_text = ""



    def callback(self, url):
        webbrowser.open_new(url)

    def __init__(self):
        self.root = tk.Tk()
        self.root.title("Data Transfer Wizard")
        self.root.iconbitmap("pepe.icns")
        self.root.geometry("800x600")        
        self.start_label = Label(self.root, text="Do you want to Upload or Download tables?")
        self.start_label.pack(pady=10)
        self.download_button=tk.Button(self.root, text="Download", command=self.start_download)
        self.download_button.pack(pady=10)

       
        self.root.mainloop()

#---------------------------------------MAIN FUNCTIONS------------------------------------------#  

    def start_download(self):
        self.function = 'download'
        for widgets in self.root.winfo_children():
            widgets.destroy()
        download_label = Label(self.root, text="Select the directory where you want to download files to")
        download_label.pack(pady=10)
        self.browse_button = tk.Button(text="Browse", command=self.browse_download_folder)
        self.browse_button.pack(pady=10)

            
    def browse_download_folder(self):
        self.download_path = filedialog.askdirectory() #This is which leads to segmentation fault 11
        #tried to solve it with the two lines below, but leads to the same error
        #prompter = promptlib.Files()
        #self.download_path = prompter.dir()
        
        if self.download_path:
            self.choose_download_table()

    def choose_download_table(self):
        self.browse_button["state"] = tk.DISABLED
        
        self.start_over_button = tk.Button(self.root, text="Return to Home", command=self.start_over, state=tk.NORMAL)
        self.start_over_button.pack(pady=10)

    def start_over(self):
        importlib.reload(databricks_odbc_tool)
        self.root.destroy()
        try:
            self.top.destroy()
        except:
            pass 
        App()
    
#--------------------------------------START APP------------------------------------------------#  

if __name__ == "__main__":
    win = App()


Current thread 0x000000010ed8e600 (most recent call first):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/commondialog.py", line 45 in show
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/filedialog.py", line 442 in askdirectory
  File "<string>", line 72 in browse_download_folder
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 1921 in __call__
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 1458 in mainloop
  File "<string>", line 57 in __init__
  File "<string>", line 102 in <module>
  File "/Users/nickyboon/Documents/GitHub/Data-Transfer-Wizard/test.py", line 87 in restart
  File "/Users/nickyboon/Documents/GitHub/Data-Transfer-Wizard/test.py", line 92 in start_over
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 1921 in __call__
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 1458 in mainloop
  File "/Users/nickyboon/Documents/GitHub/Data-Transfer-Wizard/test.py", line 57 in __init__
  File "/Users/nickyboon/Documents/GitHub/Data-Transfer-Wizard/test.py", line 102 in <module>

Extension modules: numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, pandas._libs.tslibs.dtypes, pandas._libs.tslibs.base, pandas._libs.tslibs.np_datetime, pandas._libs.tslibs.nattype, pandas._libs.tslibs.timezones, pandas._libs.tslibs.ccalendar, pandas._libs.tslibs.tzconversion, pandas._libs.tslibs.strptime, pandas._libs.tslibs.fields, pandas._libs.tslibs.timedeltas, pandas._libs.tslibs.timestamps, pandas._libs.properties, pandas._libs.tslibs.offsets, pandas._libs.tslibs.parsing, pandas._libs.tslibs.conversion, pandas._libs.tslibs.period, pandas._libs.tslibs.vectorized, pandas._libs.ops_dispatch, pandas._libs.missing, pandas._libs.hashtable, pandas._libs.algos, pandas._libs.interval, pandas._libs.tslib, pandas._libs.lib, pandas._libs.hashing, pandas._libs.ops, pandas._libs.arrays, pandas._libs.index, pandas._libs.join, pandas._libs.sparse, pandas._libs.reduction, pandas._libs.indexing, pandas._libs.internals, pandas._libs.writers, pandas._libs.window.aggregations, pandas._libs.window.indexers, pandas._libs.reshape, pandas._libs.groupby, pandas._libs.testing, pandas._libs.parsers, pandas._libs.json, PIL._imaging (total: 55)
zsh: segmentation fault  /usr/local/bin/python3 ```

Fixed by downgrading python 3.7.9

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM