JavaScript Confirm Box

test

import tkinter as tk
from tkinter import scrolledtext
from tkinter.font import Font
from PIL import ImageTk, Image
import tkinter.messagebox as messagebox
import tkinter.scrolledtext as tkscrolled
def convert_arabic_to_latin():
    arabic_word = arabic_text.get("1.0", tk.END).strip()
    converted_word = convert_arabic_to_latin_mapping(arabic_word)
    converted_word = capitalize_sentences(converted_word)
    latin_text.delete("1.0", tk.END)
    latin_text.insert(tk.END, converted_word)


def convert_arabic_to_latin_mapping(text):
    # Arabic to Latin mapping
    mapping = {
        'ت': 't',
        'و': 'w',
        'ي':'y',
        'د': 'd',
        'ا': 'a',
        'أ':'ʾa',
        'إ':'ʾe',
        'چ': 'ch',
        'ب': 'b',
        'ج': 'j',
        'ح': 'ḥ',
        'خ': 'kh',
        'ر': 'r',
        'ز': 'z',
        'س': 's',
        'ش': 'sh',
        'ڛ': 'ŝ',
        'ص': 'ṣ',
        'ض': 'ḍ',
        'ط': 'ṭ',
        'ڞ': 'ẑ',
        'ع': 'ʿ',
        'غ': 'gh',
        'ف': 'f',
        'ق': 'q',
        'ك': 'k',
        'ل': 'l',
        'ڸ': 'ḽ',
        'م': 'm',
        'ن': 'n',
        'ه': 'h',
        'ء':'ʾ',
        'ُ': 'u',
        'ِ':'e',
        'َ':'a'
        
    
    }

    converted_text = ""
    for char in text:
        if char in mapping:
            converted_text += mapping[char]
        else:
            if char=='ْ':
                continue
            if char =='ّ':
                converted_text += converted_text[len(converted_text)-1]
            else:
                converted_text += char

    return converted_text
def capitalize_sentences(text):
    sentences = text.split('. ')
    capitalized_sentences = []
    for sentence in sentences:
        capitalized_sentence = sentence.capitalize()
        capitalized_sentences.append(capitalized_sentence)
    return '. '.join(capitalized_sentences)

def clear_text():
    arabic_text.delete("1.0", tk.END)
    latin_text.delete("1.0", tk.END)

def copy_text():
    selected_text = arabic_text.selection_get() if arabic_text.focus_get() == arabic_text else latin_text.selection_get()
    if selected_text:
        window.clipboard_clear()
        window.clipboard_append(selected_text)

def paste_text():
    if arabic_text.focus_get() == arabic_text:
        text = window.clipboard_get()
        if text:
            arabic_text.insert(tk.INSERT, text)

""" def resize_background_image(event):
    new_width = event.width
    new_height = event.height
    resized_image = background_image.resize((new_width, new_height), Image.ANTIALIAS)
    global background_photo
    background_photo = ImageTk.PhotoImage(resized_image)
    background_label.config(image=background_photo) """
def on_enter_convert(event):
    convert_button.config(bg="green",fg="white")


def on_leave_convert(event):
    convert_button.config(bg="SystemButtonFace", fg="black")


def on_enter_clear(event):
    clear_button.config(bg="red", fg="white")


def on_leave_clear(event):
    clear_button.config(bg="SystemButtonFace",fg="black")




# Create the main window
window = tk.Tk()
window.title("Arabic to Latin Converter")
window.geometry("600x300")  # Set the initial size of the window (width x height)
window.configure(bg="green")
window.option_add('*text', '')

# Load the background image
background_image = Image.open("socotra.jpg")
background_image = background_image.resize((600, 300), Image.ANTIALIAS)  # Resize the image to fit the window size
background_photo = ImageTk.PhotoImage(background_image)

# Create a Label widget to display the background image
background_label = tk.Label(window, image=background_photo)
background_label.place(x=0, y=0, relwidth=1, relheight=1)

# Set custom colors
bg_color = "white"
fg_color = "black"

# Create the GUI components
arabic_label = tk.Label(window, text="Arabic Word:", font=("Arial", 14, "bold"))
arabic_text = scrolledtext.ScrolledText(window, width=35, height=5, wrap=tk.WORD, bg=bg_color, fg=fg_color,
                                        font=("Arial", 14, "bold"))
convert_button = tk.Button(window, text="Convert", command=convert_arabic_to_latin, font=("Arial", 12, "bold"))
latin_label = tk.Label(window, text="Latin:", font=("Arial", 14, "bold"))
latin_text = scrolledtext.ScrolledText(window, width=35, height=5, wrap=tk.WORD, bg=bg_color, fg=fg_color,
                                       font=("Arial", 14, "bold"))
clear_button = tk.Button(window, text="Clear", command=clear_text, font=("Arial", 12, "bold"))


# Grid layout
arabic_label.grid(row=0, column=0, padx=5, pady=5, sticky=tk.W)
arabic_text.grid(row=0, column=1, padx=5, pady=5, sticky=tk.W)
convert_button.grid(row=1, column=0, columnspan=2, padx=5, pady=5)
clear_button.grid(row=1, column=1, columnspan=2, padx=5, pady=5)
latin_label.grid(row=2, column=0, padx=5, pady=5, sticky=tk.W)
latin_text.grid(row=2, column=1, padx=5, pady=5, sticky=tk.W)
# Bind hover events to buttons
convert_button.bind("<Enter>", on_enter_convert)
convert_button.bind("<Leave>", on_leave_convert)
clear_button.bind("<Enter>", on_enter_clear)
clear_button.bind("<Leave>", on_leave_clear)
# Copy and Paste options in menu
edit_menu = tk.Menu(window)
edit_menu.add_command(label="Copy", command=copy_text)
edit_menu.add_command(label="Paste", command=paste_text)
window.config(menu=edit_menu)

# Start the main event loop
window.mainloop()