Tkinter应用程序在root.dedestroy()和第二次调用filedialog.askdirectory()后



创建了一个在Windows上运行良好的tkinter应用程序,但该应用程序似乎在特定时刻在MacOS上崩溃。

一些上下文。该应用程序在本地计算机和数据仓库之间的ODBC连接上充当GUI。成功上传/下载后,用户可以重新启动应用程序并进行另一次数据上传/下载。

在root.dedestroy((之后,应用程序再次启动,一旦用户再次选择浏览按钮,脚本第二次调用文件对话框.askdirectory((,应用程序崩溃并给出分段错误11。

编辑:我在代码下面包含了来自分段故障的错误消息有人知道如何解决这个问题吗?

请参阅下面脚本的相关部分(请不要介意导入列表(:

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 ```

通过降级python 3.7.9 修复

最新更新