Initial commit
This commit is contained in:
commit
83c902d6c3
26 changed files with 531 additions and 0 deletions
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
10
.idea/Dog_Academy.iml
generated
Normal file
10
.idea/Dog_Academy.iml
generated
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.13" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.13 (Dog_Academy)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Dog_Academy.iml" filepath="$PROJECT_DIR$/.idea/Dog_Academy.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
BIN
__pycache__/config.cpython-313.pyc
Normal file
BIN
__pycache__/config.cpython-313.pyc
Normal file
Binary file not shown.
16
config.py
Normal file
16
config.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# config.py
|
||||||
|
|
||||||
|
# Интерфейс
|
||||||
|
BACKGROUND_COLOR = "#f8e1e1"
|
||||||
|
PRIMARY_COLOR = "#ff6347"
|
||||||
|
BUTTON_COLOR = "#87ceeb"
|
||||||
|
BUTTON_TEXT_COLOR = "white"
|
||||||
|
FONT = ("Comic Sans MS", 25)
|
||||||
|
BIG_FONT = ("Comic Sans MS", 40)
|
||||||
|
|
||||||
|
# Данные для авторизации администратора
|
||||||
|
ADMIN_LOGIN = "admin"
|
||||||
|
ADMIN_PASSWORD = "admin123"
|
||||||
|
|
||||||
|
# База данных
|
||||||
|
DATABASE_URL = "sqlite:///database/DogAcademy.db" # Обновлено на правильный путь
|
||||||
BIN
database/DogAcademy.db
Normal file
BIN
database/DogAcademy.db
Normal file
Binary file not shown.
0
database/__init__.py
Normal file
0
database/__init__.py
Normal file
BIN
database/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
database/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
BIN
database/__pycache__/db_events.cpython-313.pyc
Normal file
BIN
database/__pycache__/db_events.cpython-313.pyc
Normal file
Binary file not shown.
BIN
database/__pycache__/db_session.cpython-313.pyc
Normal file
BIN
database/__pycache__/db_session.cpython-313.pyc
Normal file
Binary file not shown.
BIN
database/__pycache__/models.cpython-313.pyc
Normal file
BIN
database/__pycache__/models.cpython-313.pyc
Normal file
Binary file not shown.
28
database/db_events.py
Normal file
28
database/db_events.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
from database.db_session import get_session
|
||||||
|
from database.models import Auth
|
||||||
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
|
|
||||||
|
def create_user(login, password):
|
||||||
|
"""Создание нового пользователя в базе данных."""
|
||||||
|
session = get_session()
|
||||||
|
try:
|
||||||
|
new_user = Auth(login=login, password=password)
|
||||||
|
session.add(new_user)
|
||||||
|
session.commit()
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
print(f"Ошибка при создании пользователя: {e}")
|
||||||
|
session.rollback()
|
||||||
|
finally:
|
||||||
|
session.close()
|
||||||
|
|
||||||
|
def check_user(login, password):
|
||||||
|
"""Проверка данных пользователя для авторизации."""
|
||||||
|
session = get_session()
|
||||||
|
try:
|
||||||
|
user = session.query(Auth).filter_by(login=login, password=password).first()
|
||||||
|
return user is not None
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
print(f"Ошибка при проверке пользователя: {e}")
|
||||||
|
return False
|
||||||
|
finally:
|
||||||
|
session.close()
|
||||||
24
database/db_session.py
Normal file
24
database/db_session.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
# database/db_session.py
|
||||||
|
from sqlalchemy import create_engine
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
from config import DATABASE_URL
|
||||||
|
from database.models import Base
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Создание движка SQLAlchemy
|
||||||
|
engine = create_engine(DATABASE_URL, echo=True)
|
||||||
|
|
||||||
|
# Создание фабрики сессий
|
||||||
|
Session = sessionmaker(bind=engine)
|
||||||
|
|
||||||
|
def init_db():
|
||||||
|
"""Инициализация базы данных: создание файла и таблиц."""
|
||||||
|
if not os.path.exists("database/DogAcademy.db"):
|
||||||
|
print("База данных не найдена. Создаём новую...")
|
||||||
|
Base.metadata.create_all(bind=engine)
|
||||||
|
else:
|
||||||
|
print("База данных уже существует.")
|
||||||
|
|
||||||
|
def get_session():
|
||||||
|
"""Возвращает сессию для работы с базой данных."""
|
||||||
|
return Session()
|
||||||
55
database/models.py
Normal file
55
database/models.py
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
from sqlalchemy import Column, Integer, String, ForeignKey, Text
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
|
Base = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
|
class Auth(Base):
|
||||||
|
__tablename__ = 'auth'
|
||||||
|
user_id = Column(Integer, primary_key=True)
|
||||||
|
login = Column(String, unique=True, nullable=False)
|
||||||
|
password = Column(String, nullable=False)
|
||||||
|
|
||||||
|
# Связь с таблицей Users
|
||||||
|
user = relationship("Users", back_populates="auth", uselist=False)
|
||||||
|
|
||||||
|
|
||||||
|
class Users(Base):
|
||||||
|
__tablename__ = 'users'
|
||||||
|
user_id = Column(Integer, ForeignKey('auth.user_id'), primary_key=True)
|
||||||
|
dog_id = Column(Integer, ForeignKey('dogs.dog_id'))
|
||||||
|
username = Column(String, nullable=False)
|
||||||
|
level = Column(Integer, default=1)
|
||||||
|
achievement = Column(Text)
|
||||||
|
|
||||||
|
# Связи
|
||||||
|
auth = relationship("Auth", back_populates="user") # Обратная связь с Auth
|
||||||
|
dog = relationship("Dogs", back_populates="users") # Связь с таблицей Dogs
|
||||||
|
|
||||||
|
|
||||||
|
class Dogs(Base):
|
||||||
|
__tablename__ = 'dogs'
|
||||||
|
dog_id = Column(Integer, primary_key=True)
|
||||||
|
breed = Column(String)
|
||||||
|
characteristics = Column(Text)
|
||||||
|
behavior = Column(Text)
|
||||||
|
care_info = Column(Text)
|
||||||
|
admin_comments = Column(Text)
|
||||||
|
|
||||||
|
# Связь с таблицей Users
|
||||||
|
users = relationship("Users", back_populates="dog")
|
||||||
|
# Связь с таблицей Questions
|
||||||
|
questions = relationship("Questions", back_populates="dog")
|
||||||
|
|
||||||
|
|
||||||
|
class Questions(Base):
|
||||||
|
__tablename__ = 'questions'
|
||||||
|
question_id = Column(Integer, primary_key=True)
|
||||||
|
dog_id = Column(Integer, ForeignKey('dogs.dog_id'))
|
||||||
|
question_text = Column(Text, nullable=False)
|
||||||
|
image_url = Column(String)
|
||||||
|
helpful_info = Column(Text)
|
||||||
|
|
||||||
|
# Связь с таблицей Dogs
|
||||||
|
dog = relationship("Dogs", back_populates="questions")
|
||||||
2
requirements
Normal file
2
requirements
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
sqlalchemy
|
||||||
|
tk
|
||||||
BIN
src/__pycache__/auth.cpython-313.pyc
Normal file
BIN
src/__pycache__/auth.cpython-313.pyc
Normal file
Binary file not shown.
19
src/auth.py
Normal file
19
src/auth.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
from database.db_session import session
|
||||||
|
from database.models import Auth, Users
|
||||||
|
|
||||||
|
def register_user(login, password, username):
|
||||||
|
if session.query(Auth).filter_by(login=login).first():
|
||||||
|
return False, "Логин уже используется."
|
||||||
|
new_auth = Auth(login=login, password=password)
|
||||||
|
session.add(new_auth)
|
||||||
|
session.commit()
|
||||||
|
new_user = Users(user_id=new_auth.user_id, username=username)
|
||||||
|
session.add(new_user)
|
||||||
|
session.commit()
|
||||||
|
return True, "Регистрация успешна."
|
||||||
|
|
||||||
|
def login_user(login, password):
|
||||||
|
user = session.query(Auth).filter_by(login=login, password=password).first()
|
||||||
|
if user:
|
||||||
|
return True, user.user_id
|
||||||
|
return False, "Неверный логин или пароль."
|
||||||
16
src/main.py
Normal file
16
src/main.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
from tkinter import Tk
|
||||||
|
from src.ui.auth_ui import DogAcademyApp # Изменил на правильный путь
|
||||||
|
from database.db_session import init_db
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Основной запуск приложения."""
|
||||||
|
# Инициализируем базу данных
|
||||||
|
init_db()
|
||||||
|
|
||||||
|
# Запускаем графический интерфейс
|
||||||
|
root = Tk()
|
||||||
|
app = DogAcademyApp(root)
|
||||||
|
root.mainloop()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
BIN
src/ui/__pycache__/admin_ui.cpython-313.pyc
Normal file
BIN
src/ui/__pycache__/admin_ui.cpython-313.pyc
Normal file
Binary file not shown.
BIN
src/ui/__pycache__/auth_ui.cpython-313.pyc
Normal file
BIN
src/ui/__pycache__/auth_ui.cpython-313.pyc
Normal file
Binary file not shown.
BIN
src/ui/__pycache__/user_ui.cpython-313.pyc
Normal file
BIN
src/ui/__pycache__/user_ui.cpython-313.pyc
Normal file
Binary file not shown.
59
src/ui/admin_ui.py
Normal file
59
src/ui/admin_ui.py
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
# admin_ui.py
|
||||||
|
import tkinter as tk
|
||||||
|
from config import BACKGROUND_COLOR, PRIMARY_COLOR, BUTTON_COLOR, BUTTON_TEXT_COLOR, FONT
|
||||||
|
|
||||||
|
class AdminApp:
|
||||||
|
def __init__(self, root):
|
||||||
|
self.root = root
|
||||||
|
self.show_admin_dashboard()
|
||||||
|
|
||||||
|
def show_admin_dashboard(self):
|
||||||
|
"""Показать интерфейс администратора."""
|
||||||
|
self.clear_frame()
|
||||||
|
self.current_frame = tk.Frame(self.root, bg=BACKGROUND_COLOR)
|
||||||
|
self.current_frame.pack(expand=True)
|
||||||
|
|
||||||
|
# Заголовок
|
||||||
|
title = tk.Label(
|
||||||
|
self.current_frame,
|
||||||
|
text="Админ-Панель",
|
||||||
|
bg=BACKGROUND_COLOR,
|
||||||
|
fg=PRIMARY_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
)
|
||||||
|
title.pack(pady=50)
|
||||||
|
|
||||||
|
# Кнопка для управления вопросами
|
||||||
|
manage_questions_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Управление вопросами",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.manage_questions,
|
||||||
|
)
|
||||||
|
manage_questions_button.pack(pady=20)
|
||||||
|
|
||||||
|
# Кнопка для управления пользователями
|
||||||
|
manage_users_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Управление пользователями",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.manage_users,
|
||||||
|
)
|
||||||
|
manage_users_button.pack(pady=20)
|
||||||
|
|
||||||
|
def manage_questions(self):
|
||||||
|
"""Управление вопросами в игре."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def manage_users(self):
|
||||||
|
"""Управление пользователями игры."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def clear_frame(self):
|
||||||
|
"""Очистить текущий фрейм."""
|
||||||
|
if hasattr(self, 'current_frame') and self.current_frame:
|
||||||
|
self.current_frame.destroy()
|
||||||
222
src/ui/auth_ui.py
Normal file
222
src/ui/auth_ui.py
Normal file
|
|
@ -0,0 +1,222 @@
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import messagebox
|
||||||
|
from config import BACKGROUND_COLOR, PRIMARY_COLOR, BUTTON_COLOR, BUTTON_TEXT_COLOR, FONT, BIG_FONT, ADMIN_LOGIN, ADMIN_PASSWORD
|
||||||
|
from src.ui.admin_ui import AdminApp # Импорт интерфейса администратора
|
||||||
|
from database.db_events import create_user, check_user
|
||||||
|
from src.ui.user_ui import UserApp
|
||||||
|
|
||||||
|
class DogAcademyApp:
|
||||||
|
def __init__(self, root):
|
||||||
|
self.root = root
|
||||||
|
self.root.title("Dog Academy Game")
|
||||||
|
self.root.geometry("1920x1080")
|
||||||
|
self.root.configure(bg=BACKGROUND_COLOR)
|
||||||
|
self.current_frame = None
|
||||||
|
self.show_main_menu()
|
||||||
|
|
||||||
|
def clear_frame(self):
|
||||||
|
"""Очистить текущий фрейм."""
|
||||||
|
if self.current_frame:
|
||||||
|
self.current_frame.destroy()
|
||||||
|
|
||||||
|
def show_main_menu(self):
|
||||||
|
"""Показать главное меню с названием игры и кнопками."""
|
||||||
|
self.clear_frame()
|
||||||
|
self.current_frame = tk.Frame(self.root, bg=BACKGROUND_COLOR)
|
||||||
|
self.current_frame.pack(expand=True)
|
||||||
|
|
||||||
|
# Название игры
|
||||||
|
title = tk.Label(
|
||||||
|
self.current_frame,
|
||||||
|
text="Dog Academy Game",
|
||||||
|
bg=BACKGROUND_COLOR,
|
||||||
|
fg=PRIMARY_COLOR,
|
||||||
|
font=BIG_FONT,
|
||||||
|
)
|
||||||
|
title.pack(pady=50)
|
||||||
|
|
||||||
|
# Кнопка "Войти"
|
||||||
|
login_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Войти",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.show_login_screen,
|
||||||
|
)
|
||||||
|
login_button.pack(pady=20)
|
||||||
|
|
||||||
|
# Кнопка "Зарегистрироваться"
|
||||||
|
register_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Зарегистрироваться",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.show_registration_screen,
|
||||||
|
)
|
||||||
|
register_button.pack(pady=20)
|
||||||
|
|
||||||
|
def show_login_screen(self):
|
||||||
|
"""Показать экран авторизации."""
|
||||||
|
self.clear_frame()
|
||||||
|
self.current_frame = tk.Frame(self.root, bg=BACKGROUND_COLOR)
|
||||||
|
self.current_frame.pack(expand=True)
|
||||||
|
|
||||||
|
# Заголовок
|
||||||
|
title = tk.Label(
|
||||||
|
self.current_frame,
|
||||||
|
text="Авторизация",
|
||||||
|
bg=BACKGROUND_COLOR,
|
||||||
|
fg=PRIMARY_COLOR,
|
||||||
|
font=BIG_FONT,
|
||||||
|
)
|
||||||
|
title.pack(pady=50)
|
||||||
|
|
||||||
|
# Логин
|
||||||
|
self.login_entry = tk.Entry(self.current_frame, font=FONT)
|
||||||
|
self.login_entry.pack(pady=10)
|
||||||
|
|
||||||
|
# Пароль
|
||||||
|
self.password_entry = tk.Entry(self.current_frame, show="*", font=FONT)
|
||||||
|
self.password_entry.pack(pady=10)
|
||||||
|
|
||||||
|
# Кнопка "Показать пароль"
|
||||||
|
show_password_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Показать пароль",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.toggle_password,
|
||||||
|
)
|
||||||
|
show_password_button.pack(pady=10)
|
||||||
|
|
||||||
|
# Кнопка "Войти"
|
||||||
|
login_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Войти",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.login_user,
|
||||||
|
)
|
||||||
|
login_button.pack(pady=20)
|
||||||
|
|
||||||
|
# Кнопка "Вернуться на главную"
|
||||||
|
back_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Вернуться на главную",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.show_main_menu,
|
||||||
|
)
|
||||||
|
back_button.pack(pady=20)
|
||||||
|
|
||||||
|
def toggle_password(self):
|
||||||
|
"""Переключение видимости пароля."""
|
||||||
|
if self.password_entry.cget('show') == '*':
|
||||||
|
self.password_entry.config(show='')
|
||||||
|
else:
|
||||||
|
self.password_entry.config(show='*')
|
||||||
|
|
||||||
|
def login_user(self):
|
||||||
|
"""Проверка данных для авторизации."""
|
||||||
|
login = self.login_entry.get()
|
||||||
|
password = self.password_entry.get()
|
||||||
|
|
||||||
|
if login == ADMIN_LOGIN and password == ADMIN_PASSWORD:
|
||||||
|
messagebox.showinfo("Успех", "Вы успешно авторизованы как администратор!")
|
||||||
|
self.show_admin_panel() # Переходим к админ-панели
|
||||||
|
elif check_user(login, password):
|
||||||
|
messagebox.showinfo("Успех", "Вы успешно авторизованы!")
|
||||||
|
self.show_user_dashboard() # Переходим к панели пользователя
|
||||||
|
else:
|
||||||
|
messagebox.showerror("Ошибка", "Неверные данные. Попробуйте снова.")
|
||||||
|
|
||||||
|
def show_admin_panel(self):
|
||||||
|
"""Отображение интерфейса администратора."""
|
||||||
|
self.clear_frame()
|
||||||
|
AdminApp(self.root) # Создаем экземпляр админ-панели
|
||||||
|
|
||||||
|
def show_registration_screen(self):
|
||||||
|
"""Показать экран регистрации."""
|
||||||
|
self.clear_frame()
|
||||||
|
self.current_frame = tk.Frame(self.root, bg=BACKGROUND_COLOR)
|
||||||
|
self.current_frame.pack(expand=True)
|
||||||
|
|
||||||
|
# Заголовок
|
||||||
|
title = tk.Label(
|
||||||
|
self.current_frame,
|
||||||
|
text="Регистрация",
|
||||||
|
bg=BACKGROUND_COLOR,
|
||||||
|
fg=PRIMARY_COLOR,
|
||||||
|
font=BIG_FONT,
|
||||||
|
)
|
||||||
|
title.pack(pady=50)
|
||||||
|
|
||||||
|
# Логин
|
||||||
|
self.reg_login_entry = tk.Entry(self.current_frame, font=FONT)
|
||||||
|
self.reg_login_entry.pack(pady=10)
|
||||||
|
|
||||||
|
# Пароль
|
||||||
|
self.reg_password_entry = tk.Entry(self.current_frame, show="*", font=FONT)
|
||||||
|
self.reg_password_entry.pack(pady=10)
|
||||||
|
|
||||||
|
# Кнопка "Показать пароль"
|
||||||
|
show_password_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Показать пароль",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.toggle_registration_password,
|
||||||
|
)
|
||||||
|
show_password_button.pack(pady=10)
|
||||||
|
|
||||||
|
# Кнопка "Зарегистрироваться"
|
||||||
|
register_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Зарегистрироваться",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.register_user,
|
||||||
|
)
|
||||||
|
register_button.pack(pady=20)
|
||||||
|
|
||||||
|
# Кнопка "Вернуться на главную"
|
||||||
|
back_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Вернуться на главную",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.show_main_menu,
|
||||||
|
)
|
||||||
|
back_button.pack(pady=20)
|
||||||
|
|
||||||
|
def toggle_registration_password(self):
|
||||||
|
"""Переключение видимости пароля для регистрации."""
|
||||||
|
if self.reg_password_entry.cget('show') == '*':
|
||||||
|
self.reg_password_entry.config(show='')
|
||||||
|
else:
|
||||||
|
self.reg_password_entry.config(show='*')
|
||||||
|
|
||||||
|
def register_user(self):
|
||||||
|
"""Регистрация нового пользователя."""
|
||||||
|
login = self.reg_login_entry.get()
|
||||||
|
password = self.reg_password_entry.get()
|
||||||
|
|
||||||
|
if login and password:
|
||||||
|
create_user(login, password)
|
||||||
|
messagebox.showinfo("Успех", "Вы успешно зарегистрированы!")
|
||||||
|
self.show_login_screen()
|
||||||
|
else:
|
||||||
|
messagebox.showerror("Ошибка", "Пожалуйста, заполните все поля.")
|
||||||
|
|
||||||
|
def show_user_dashboard(self):
|
||||||
|
"""Перейти к главному меню пользователя после авторизации."""
|
||||||
|
UserApp(self.root, self)
|
||||||
|
|
||||||
56
src/ui/user_ui.py
Normal file
56
src/ui/user_ui.py
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
import tkinter as tk
|
||||||
|
from config import BACKGROUND_COLOR, PRIMARY_COLOR, BUTTON_COLOR, BUTTON_TEXT_COLOR, FONT
|
||||||
|
|
||||||
|
class UserApp:
|
||||||
|
def __init__(self, root, dog_academy_app):
|
||||||
|
self.root = root
|
||||||
|
self.dog_academy_app = dog_academy_app # Сохраняем ссылку на DogAcademyApp
|
||||||
|
self.show_user_dashboard()
|
||||||
|
|
||||||
|
def show_user_dashboard(self):
|
||||||
|
"""Показать интерфейс пользователя."""
|
||||||
|
self.clear_frame()
|
||||||
|
self.current_frame = tk.Frame(self.root, bg=BACKGROUND_COLOR)
|
||||||
|
self.current_frame.pack(expand=True)
|
||||||
|
|
||||||
|
# Заголовок
|
||||||
|
title = tk.Label(
|
||||||
|
self.current_frame,
|
||||||
|
text="Главное меню",
|
||||||
|
bg=BACKGROUND_COLOR,
|
||||||
|
fg=PRIMARY_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
)
|
||||||
|
title.pack(pady=50)
|
||||||
|
|
||||||
|
# Кнопка "Играть"
|
||||||
|
play_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Играть",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.play_game,
|
||||||
|
)
|
||||||
|
play_button.pack(pady=20)
|
||||||
|
|
||||||
|
# Кнопка "Выход"
|
||||||
|
logout_button = tk.Button(
|
||||||
|
self.current_frame,
|
||||||
|
text="Выход",
|
||||||
|
bg=BUTTON_COLOR,
|
||||||
|
fg=BUTTON_TEXT_COLOR,
|
||||||
|
font=FONT,
|
||||||
|
command=self.dog_academy_app.show_main_menu, # Вызываем метод из DogAcademyApp
|
||||||
|
)
|
||||||
|
logout_button.pack(pady=20)
|
||||||
|
|
||||||
|
def play_game(self):
|
||||||
|
"""Запуск игры."""
|
||||||
|
# TODO: Логика игры
|
||||||
|
pass
|
||||||
|
|
||||||
|
def clear_frame(self):
|
||||||
|
"""Очистить текущий фрейм."""
|
||||||
|
if hasattr(self, 'current_frame') and self.current_frame:
|
||||||
|
self.current_frame.destroy()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue