使用Python for Loop无法找到的“不可见文件”

时间:2018-05-31 00:06:38

标签: python python-3.x user-interface tkinter subprocess

我正在尝试搜索我的根目录的所有子目录中的所有文件,以输出包含用户输入的“key_phrases”的行。我当前的代码可以查找和输出我的子目录中的大多数文件的行,但我似乎无法在文件夹的某些文件中找到行,几乎就像它们对搜索不可见。下面是我的python函数和Tkinter GUI的代码,供用户输入目录和关键短语。 Tkinter GUI仅供参考,我相信问题出在我的Python函数的for循环中。

我的Python函数

from searchandOutput import searchandOutput 
from tkinter import *
from tkinter import ttk
from tkinter import messagebox

class Feedback:

    def __init__(self, master):

        master.title('Search and Output')
        master.resizable(False, False)
        master.configure(background = '#ffffff')

        self.frame_header = ttk.Frame(master)
        self.frame_header.pack()

        self.style = ttk.Style()
        self.style.configure('TFrame', background = '#ffffff')
        self.style.configure('TButton', background = '#ffffff')
        self.style.configure('TLabel', background = '#ffffff', font = ('Arial', 11))

        ttk.Label(self.frame_header, wraplength = 300, text = "Output the desired lines from the logs in the directory by entering the following.").grid(row = 0, column = 1) 

        self.frame_content = ttk.Frame(master)
        self.frame_content.pack()

        ttk.Label(self.frame_content, text = 'Root Directory:').grid(row = 0, column = 0, pady = 4)
        #ttk.Label(self.frame_content, text = 'Applicable File Types:').grid(row = 1, column = 0)          
        ttk.Label(self.frame_content, text = 'Key Phrase:').grid(row = 2, column = 0) 

        self.entry_rootdirectory = ttk.Entry(self.frame_content, width = 35, font = ('Arial', 10))
        self.text_keyphrase = Text(self.frame_content, width = 35, height = 5, font = ('Arial', 10))
        #self.text_filetypes = Text(self.frame_content, width = 35, height = 5, font = ('Arial', 10))

        self.entry_rootdirectory.grid(row = 0, column = 1)
        #self.text_filetypes.grid(row = 1, column = 1)
        self.text_keyphrase.grid(row = 2, column = 1)

        ttk.Button(self.frame_content, text = 'Submit', command = self.submit).grid(row = 5, column = 0, pady = 5)
        ttk.Button(self.frame_content, text = 'Clear', command = self.clear).grid(row = 5, column = 1, pady = 5)




    def submit(self):
        #Enter code that connects to the python script here
        rootd = self.entry_rootdirectory.get()
        keyp = self.text_keyphrase.get(1.0, 'end')
        searchandOutput(rootd, keyp)
        messagebox.showinfo(title = "Search Requested", message = "Search Completed!")


    def clear(self):
        self.entry_rootdirectory.delete(0, 'end')
        #self.text_filetypes.delete(1.0, 'end')
        self.text_keyphrase.delete(1.0, 'end') 

def main():

    root = Tk()
    feedback = Feedback(root)
    root.mainloop()

if __name__ == "__main__": main() 

我的TKinter GUI

class EventPublisher {

    public event EventHandler Event;
}

class EventSubscriber {

    public void Handler(object sender, EventArgs e) { }
}

class Glue {

    private EventPublisher _publisher = new EventPublisher();

    private EventSubscriber _subscriber = new EventSubscriber();


    public Glue() {
        _publisher.Event += _subscriber.Handler;
    }
}

0 个答案:

没有答案