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


import tkinter as tk
from tkinter import ttk, messagebox

# Курсы валют — константы
USD = 80
EUR = 90
CNY = 11


# Функция конвертации
def convert():
    try:
        rubles = float(entry_rubles.get())

        if rubles < 0:
            messagebox.showerror("Ошибка", "Сумма не может быть отрицательной")
            return

        currency = combo_currency.get()

        if currency == "USD":
            result = rubles / USD
        elif currency == "EUR":
            result = rubles / EUR
        elif currency == "CNY":
            result = rubles / CNY
        else:
            messagebox.showwarning("Внимание", "Выберите валюту")
            return

        result_label.config(
            text=f"Результат: {result:.2f} {currency}"
        )

    except ValueError:
        messagebox.showerror("Ошибка", "Введите число")


# Создание окна
window = tk.Tk()
window.title("Конвертер валют")
window.geometry("400x300")
window.resizable(False, False)


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


# Поле для рублей
label_rubles = tk.Label(
    window,
    text="Сумма в рублях:"
)
label_rubles.pack()

entry_rubles = tk.Entry(
    window,
    width=25
)
entry_rubles.pack(pady=5)


# Выбор валюты
label_currency = tk.Label(
    window,
    text="Выберите валюту:"
)
label_currency.pack(pady=(10, 0))

combo_currency = ttk.Combobox(
    window,
    values=["USD", "EUR", "CNY"],
    state="readonly",
    width=22
)
combo_currency.pack(pady=5)
combo_currency.current(0)


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


# Вывод результата
result_label = tk.Label(
    window,
    text="Результат: ",
    font=("Arial", 12, "bold")
)
result_label.pack(pady=5)


# Запуск программы
window.mainloop()