由于我正在使用线程,因此我试图从类外的函数中将文本插入文本框。
代码:
import os
import glob
import threading
from Tkinter import *
import Tkinter as tk
import ScrolledText as tkst
def searchfunc(string, filetype, directory):
print 'string : '+string
print 'filetype : '+filetype
print 'directory : '+directory
os.chdir(directory)
for file in glob.glob('*'+filetype):
if string in open(file).read():
print '[-info-] textstring found in >> '+file
searchresults.insert(INSERT, file) # problem line
else:
print '[-info-] text string not found in : '+file
pass
class name:
def __init__(self, top=None):
...
def search():
string = self.stringtextbox.get()
filetype = self.filetypetextbox.get()
directory = self.directorytextbox.get()
t = threading.Thread(target=searchfunc(string, filetype, directory))
t.daemon = True
t.start()
但是它给了我以下错误:
NameError: global name 'searchresults' is not defined
当然,如果我使用名称“ self.searchresults”也会给我一个错误,因为您知道self是类本身的一个双引子