我用windnd模块做了个文件拖入获取路径的功能,想把获取到的路径插入到列表,但是GUI会崩溃,下面是原代码 求大佬帮忙看看咋回事
[Python] 纯文本查看 复制代码 import windnd
import threading
import tkinter as tk
class TestGui:
def __init__(self, init_window_name):
self.init_window_name = init_window_name
self.init_window_name.title("测试")
self.init_window_name.geometry("580x340+600+350")
self.scroll_y = tk.Scrollbar(self.init_window_name)
self.scroll_y.grid(row=0, column=2, ipady=100)
self.listbox1 = tk.Listbox(self.init_window_name, width=80, height=13, yscrollcommand=self.scroll_y.set)
self.listbox1.grid(row=0, column=1,columnspan=1)
self.scroll_y.config(command=self.listbox1.yview)
self.listbox1.insert(tk.END, "99999") # 能正常插入列表框
""" 列表框及滚动条 """
self.hook_dropfiles = windnd.hook_dropfiles
self.hook_dropfiles(self.listbox1, func=self.dragged_files)
""" 文件拖动 """
def thread_it(self, func, *args):
self.myThread = threading.Thread(target=func, args=args)
self.myThread .setDaemon(True)
self.myThread .start()
def dragged_files(self,files):
msg = '\n'.join((item.decode('gbk') for item in files))
print(msg) # 把文件拖进来后可以正常打印路径
self.listbox1.insert(tk.END, msg) # 但一插入列表 GUI就崩溃了
if __name__ == '__main__':
init_window = tk.Tk()
init_window.attributes("-topmost", 1)
test_gui = TestGui(init_window)
init_window.mainloop()
报了这个错误 :Fatal Python error: PyEval_RestoreThread: NULL tstate
Python runtime state: initialized |