Ulyprian Analyzer Python GUI
👤 Sharing: AI
import tkinter as tk
from tkinter import ttk
import json
import re
from collections import Counter
class TextAnalyzerApp:
def __init__(self, master):
self.master = master
master.title("Ulyprian Analyzer")
master.geometry("800x600")
self.notebook = ttk.Notebook(master)
self.notebook.pack(fill="both", expand=True)
# Text Analysis Tab
self.text_tab = ttk.Frame(self.notebook)
self.notebook.add(self.text_tab, text='Text Analysis')
self.text_input = tk.Text(self.text_tab, height=15, width=80)
self.text_input.pack(pady=10, padx=10)
self.analyze_button = tk.Button(self.text_tab, text="Analyze Text", command=self.analyze_text)
self.analyze_button.pack(pady=5)
self.text_output = tk.Text(self.text_tab, height=10, width=80)
self.text_output.pack(pady=10, padx=10)
# JSON Analysis Tab
self.json_tab = ttk.Frame(self.notebook)
self.notebook.add(self.json_tab, text='JSON Analysis')
self.json_input = tk.Text(self.json_tab, height=15, width=80)
self.json_input.pack(pady=10, padx=10)
self.json_analyze_button = tk.Button(self.json_tab, text="Analyze JSON", command=self.analyze_json)
self.json_analyze_button.pack(pady=5)
self.json_output = tk.Text(self.json_tab, height=10, width=80)
self.json_output.pack(pady=10, padx=10)
# Regex Tab
self.regex_tab = ttk.Frame(self.notebook)
self.notebook.add(self.regex_tab, text='Regex Search')
self.regex_input = tk.Entry(self.regex_tab, width=80)
self.regex_input.pack(pady=5, padx=10)
self.regex_text_input = tk.Text(self.regex_tab, height=10, width=80)
self.regex_text_input.pack(pady=5, padx=10)
self.regex_search_button = tk.Button(self.regex_tab, text="Search Regex", command=self.search_regex)
self.regex_search_button.pack(pady=5)
self.regex_output = tk.Text(self.regex_tab, height=5, width=80)
self.regex_output.pack(pady=5, padx=10)
#Details Button
self.details_button = tk.Button(master, text="Details", command=self.show_details)
self.details_button.pack(pady=10)
def analyze_text(self):
text = self.text_input.get("1.0", tk.END)
word_count = len(text.split())
char_count = len(text)
sentences = re.split(r'[.!?]+', text)
sentence_count = len([s for s in sentences if s.strip()])
word_lengths = [len(word) for word in text.split()] # Calculate word lengths
if word_lengths:
average_word_length = sum(word_lengths) / len(word_lengths)
else:
average_word_length = 0
self.text_output.delete("1.0", tk.END)
self.text_output.insert(tk.END, f"Word Count: {word_count}\n")
self.text_output.insert(tk.END, f"Character Count: {char_count}\n")
self.text_output.insert(tk.END, f"Sentence Count: {sentence_count}\n")
self.text_output.insert(tk.END, f"Average Word Length: {average_word_length:.2f}\n") # Output average word length
words = re.findall(r'\b\w+\b', text.lower()) #Extract words
word_frequency = Counter(words)
most_common_words = word_frequency.most_common(5)
self.text_output.insert(tk.END, f"\nMost Common Words: {most_common_words}\n")
def analyze_json(self):
try:
json_text = self.json_input.get("1.0", tk.END)
data = json.loads(json_text)
self.json_output.delete("1.0", tk.END)
self.json_output.insert(tk.END, json.dumps(data, indent=4))
except json.JSONDecodeError as e:
self.json_output.delete("1.0", tk.END)
self.json_output.insert(tk.END, f"Error decoding JSON: {e}")
def search_regex(self):
regex = self.regex_input.get()
text = self.regex_text_input.get("1.0", tk.END)
try:
matches = re.findall(regex, text)
self.regex_output.delete("1.0", tk.END)
if matches:
self.regex_output.insert(tk.END, "Matches:\n")
for match in matches:
self.regex_output.insert(tk.END, f"{match}\n")
else:
self.regex_output.insert(tk.END, "No matches found.")
except re.error as e:
self.regex_output.delete("1.0", tk.END)
self.regex_output.insert(tk.END, f"Invalid regex: {e}")
def show_details(self):
details_window = tk.Toplevel(self.master)
details_window.title("Program Details")
details_text = tk.Text(details_window, height=20, width=80)
details_text.pack(padx=10, pady=10)
details_text.insert(tk.END, """
Ulyprian Analyzer: A versatile tool for text, JSON, and regex analysis.
Text Analysis:
Analyzes text input to provide word count, character count, sentence count,
average word length, and the most frequent words.
JSON Analysis:
Parses and validates JSON input, displaying a formatted version or error messages.
Regex Search:
Allows users to search for patterns within text using regular expressions,
displaying any matches found.
This program is designed to be a handy utility for anyone working with text data,
JSON files, or needing to perform regex searches quickly.
""")
details_text.config(state=tk.DISABLED) #Make it read only
root = tk.Tk()
app = TextAnalyzerApp(root)
root.mainloop()
👁️ Viewed: 5
Comments