给这串代码添加清洁好看扁平化的用户界面UI:import osfrom tkinter import Tk filedialogdef scan_directorypath for root dirs files in oswalkpath for file in files file_path = ospathjoinroot file
以下是给代码添加清洁好看扁平化的用户界面UI后的代码:
import os
from tkinter import Tk, filedialog
from tkinter import messagebox
def scan_directory(path):
infected_files = []
for root, dirs, files in os.walk(path):
for file in files:
file_path = os.path.join(root, file)
if is_infected(file_path):
infected_files.append(file_path)
if infected_files:
messagebox.showinfo("病毒扫描结果", f"发现以下病毒文件:\n\n{', '.join(infected_files)}")
else:
messagebox.showinfo("病毒扫描结果", "未发现病毒文件")
def is_infected(file_path):
# 这里可以添加你的病毒检测逻辑
# 返回True表示文件被感染,返回False表示文件未被感染
return False
def select_directory():
root = Tk()
root.withdraw()
path = filedialog.askdirectory()
return path
if __name__ == "__main__":
path = select_directory()
if path:
scan_directory(path)
这个修改后的代码使用messagebox模块替代了print语句,以弹出消息框显示病毒扫描结果。如果发现病毒文件,将会显示一个消息框,列出所有病毒文件的路径。如果未发现病毒文件,将会显示一个消息框,提示未发现病毒文件
原文地址: https://www.cveoy.top/t/topic/iqJC 著作权归作者所有。请勿转载和采集!