def check_file():
file_path = filedialog.askopenfilename(filetypes=[('Text files', '*.txt')])
if file_path:
count_respect_format = 0
count_do_not_respect_format = 0
invalid_strings = []
with open(file_path, 'r') as file:
content = file.read()
pairs = content.split('\n\n')
for pair in pairs:
strings = pair.strip().split('\n')
if len(strings) == 2:
string1, string2 = strings
if check_format(string1.strip()) and check_format(string2.strip()):
count_respect_format += 1
else:
count_do_not_respect_format += 1
invalid_strings.append((string1.strip(), string2.strip()))
else:
print(f"Skipping pair: {pair}")
result_text.delete('1.0', 'end')
result_text.insert('end', f"Number of pairs that respect the format: {count_respect_format}\n"
f"Number of pairs that do not respect the format: {count_do_not_respect_format}\n\n")
if count_do_not_respect_format > 0:
result_text.insert('end', "Invalid strings:\n\n")
for invalid_string in invalid_strings:
result_text.insert('end', f"{invalid_string[0]}\n{invalid_string[1]}\n\n")
else:
result_text.delete('1.0', 'end')
result_text.insert('end', "No file selected.")