如何使用模块" re"在文本框中显示文本文件的内容

时间:2018-01-23 06:05:11

标签: python tkinter

我正在做关于Aircrack-ng GUI的最后一年项目。在我的GUI设计中,破解密码的结果将写入文本文件。我编写代码来读取文本文件并显示我需要的内容。现在我可以在测试框上显示一些信息(目标AP,ESSID,KEY)。我还需要显示ASCII密码。我必须参考有关re(https://docs.python.org/2/library/re.html)的文档并尝试但不成功。我希望有人可以教我怎么做。谢谢。

这是关于破解密码

的结果的文本文件

https://drive.google.com/open?id=192IQr5Y2VUjIZBdUrAlD5uyQQ8YSOUDw

这是关于显示wep密码

的详细信息的功能和GUI设计
# Use pandas to filter the results and display to textbox
       def wepresult():
               result = re.search(r"\[([^[]+[^(])\]", wepcrackresult_text.get("1.0", 'end-1c'))
               if result:
                   wepcrackresult_text.delete(0.0, END)
                   wepcrackresult_text.insert(INSERT, "Target ESSID: " + self.controller.shared_data[
                       "ESSID"].get() + "\nTarget MAC address: " + self.controller.shared_data[
                                                  "BSSID"].get() + "\nKEY:" + result.group(1))

GUI设计

wepcrackresult_button = tk.Button(self, text='4.Check', font='Verdana 14',command = wepresult)
wepcrackresult_button.place(x=2, y=630)

1 个答案:

答案 0 :(得分:0)

以下是我能想到的最简单的代码:

import tkinter as tk


def display_file(file_path):
    txt.delete('1.0', 'end')
    with open(file_path) as f:
        file_content_as_string = f.read()
    # regex filterings can be made in filte_content_as_string
    txt.insert('1.0', file_content_as_string)

if __name__ == '__main__':
    root = tk.Tk()
    txt = tk.Text(root)

    # replace __file__ with path
    display_file(__file__)

    txt.pack()
    root.mainloop()
相关问题