Загрузка данных


import tkinter as tk
from tkinter import messagebox
import random
import string


# Функция генерации пароля
def generate_password():
    try:
        length = int(spin_length.get())

        if not check_digits.get() and not check_letters.get() and not check_symbols.get():
            messagebox.showwarning("Ошибка", "Выберите хотя бы один тип символов")
            return

        characters = ""

        if check_digits.get():
            characters += string.digits

        if check_letters.get():
            characters += string.ascii_letters

        if check_symbols.get():
            characters += "!@#$%^&*"

        password = ""

        for i in range(length):
            password += random.choice(characters)

        entry_password.delete(0, tk.END)
        entry_password.insert(0, password)

    except ValueError:
        messagebox.showerror("Ошибка", "Введите правильную длину")


# Главное окно
window = tk.Tk()
window.title("Генератор паролей")
window.geometry("400x350")
window.resizable(False, False)


# Заголовок
label_title = tk.Label(
    window,
    text="Генератор паролей",
    font=("Arial", 18, "bold")
)
label_title.pack(pady=15)


# Длина пароля
label_length = tk.Label(
    window,
    text="Длина пароля:"
)
label_length.pack()

spin_length = tk.Spinbox(
    window,
    from_=4,
    to=30,
    width=10
)
spin_length.pack(pady=5)


# Флажки
check_digits = tk.BooleanVar(value=True)
check_letters = tk.BooleanVar(value=True)
check_symbols = tk.BooleanVar(value=False)


checkbutton_digits = tk.Checkbutton(
    window,
    text="Цифры",
    variable=check_digits
)
checkbutton_digits.pack()


checkbutton_letters = tk.Checkbutton(
    window,
    text="Буквы",
    variable=check_letters
)
checkbutton_letters.pack()


checkbutton_symbols = tk.Checkbutton(
    window,
    text="Символы",
    variable=check_symbols
)
checkbutton_symbols.pack()


# Кнопка
button_generate = tk.Button(
    window,
    text="Сгенерировать",
    command=generate_password,
    width=20
)
button_generate.pack(pady=15)


# Поле для вывода пароля
entry_password = tk.Entry(
    window,
    width=30,
    justify="center"
)
entry_password.pack()


# Запуск
window.mainloop()