카테고리 없음
ㄱㅇㅇㄱ
1231.
2025. 2. 24. 11:08
import tkinter as tk
from tkinter import ttk, scrolledtext
import requests
from Cryptodome.Cipher import AES
from Cryptodome.Util.Padding import pad, unpad
import base64
import threading
import time
import random
import string
class ConsoleStyle:
BG_COLOR = 'black'
FG_COLOR = '#00ff00' # 연한 녹색 (터미널 스타일)
FONT = ('Consolas', 10) # 고정폭 폰트
CURSOR_COLOR = '#00ff00'
SELECT_BG = '#003300' # 선택 영역 배경색
SELECT_FG = '#00ff00' # 선택 영역 텍스트색
class ChatClientGUI:
def __init__(self, root):
self.root = root
self.root.title("Secure Terminal Chat")
self.setup_gui()
self.setup_client()
self.apply_console_style()
self.setup_shortcuts() # 단축키 설정 추가
# 타임워치 변수 초기화
self.start_time = None
self.is_timing = False
def setup_shortcuts(self):
# Ctrl+O 단축키 바인딩
self.root.bind('<Control-o>', lambda e: self.clear_chat())
# F2, F4 타임워치 바인딩
self.root.bind('<F2>', lambda e: self.start_timer())
self.root.bind('<F4>', lambda e: self.stop_timer())
def start_timer(self):
if not self.is_timing:
self.start_time = time.time()
self.is_timing = True
self.show_system_message("타임워치 시작")
def stop_timer(self):
if self.is_timing and self.start_time is not None:
elapsed_time = time.time() - self.start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
time_str = f"{hours:02d}:{minutes:02d}:{seconds:02d}"
self.show_system_message(f"경과 시간: {time_str}")
self.is_timing = False
self.start_time = None
def clear_chat(self):
# 채팅 영역의 모든 내용을 삭제
self.chat_area.delete(1.0, tk.END)
self.show_system_message("대화 내용이 삭제되었습니다.")
def apply_console_style(self):
# 윈도우 스타일
self.root.configure(bg=ConsoleStyle.BG_COLOR)
# 스타일 설정
style = ttk.Style()
style.configure('Console.TFrame', background=ConsoleStyle.BG_COLOR)
style.configure('Console.TLabel',
background=ConsoleStyle.BG_COLOR,
foreground=ConsoleStyle.FG_COLOR,
font=ConsoleStyle.FONT)
style.configure('Console.TButton',
background=ConsoleStyle.BG_COLOR,
foreground=ConsoleStyle.FG_COLOR,
font=ConsoleStyle.FONT)
style.configure('Console.TEntry',
background=ConsoleStyle.BG_COLOR,
foreground=ConsoleStyle.FG_COLOR,
font=ConsoleStyle.FONT,
fieldbackground=ConsoleStyle.BG_COLOR)
# 채팅 영역 스타일
self.chat_area.configure(
bg=ConsoleStyle.BG_COLOR,
fg=ConsoleStyle.FG_COLOR,
font=ConsoleStyle.FONT,
insertbackground=ConsoleStyle.CURSOR_COLOR,
selectbackground=ConsoleStyle.SELECT_BG,
selectforeground=ConsoleStyle.SELECT_FG
)
# 입력 영역 스타일
self.message_entry.configure(
style='Console.TEntry',
font=ConsoleStyle.FONT
)
def setup_client(self):
self.client_id = self.generate_client_id()
self.running = True
self.server_url = None
# 서버 연결 프레임
self.connect_frame = ttk.Frame(self.root, padding="10", style='Console.TFrame')
self.connect_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
ttk.Label(self.connect_frame, text="서버 IP:", style='Console.TLabel').grid(row=0, column=0, padx=5)
self.server_ip = ttk.Entry(self.connect_frame, width=20, style='Console.TEntry')
self.server_ip.insert(0, "localhost")
self.server_ip.grid(row=0, column=1, padx=5)
self.connect_btn = ttk.Button(self.connect_frame, text="연결",
command=self.connect_to_server,
style='Console.TButton')
self.connect_btn.grid(row=0, column=2, padx=5)
# 메시지 영역은 처음에는 숨김
self.message_frame.grid_remove()
def setup_gui(self):
# 메시지 프레임
self.message_frame = ttk.Frame(self.root, padding="10", style='Console.TFrame')
self.message_frame.grid(row=1, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
# 채팅 영역
self.chat_area = scrolledtext.ScrolledText(
self.message_frame,
wrap=tk.WORD,
width=80, # 더 넓게
height=24 # 더 높게
)
self.chat_area.grid(row=0, column=0, columnspan=2, sticky=(tk.W, tk.E, tk.N, tk.S))
# 메시지 입력
self.message_entry = ttk.Entry(
self.message_frame,
style='Console.TEntry',
width=70 # 더 넓게
)
self.message_entry.grid(row=1, column=0, sticky=(tk.W, tk.E), padx=5, pady=5)
self.message_entry.bind('<Return>', lambda e: self.send_message())
# 전송 버튼
self.send_button = ttk.Button(
self.message_frame,
text="전송",
command=self.send_message,
style='Console.TButton'
)
self.send_button.grid(row=1, column=1, sticky=(tk.E), pady=5)
# Grid 설정
self.root.columnconfigure(0, weight=1)
self.root.rowconfigure(1, weight=1)
self.message_frame.columnconfigure(0, weight=1)
# ... (나머지 메서드들은 동일하게 유지)
def main():
root = tk.Tk()
root.configure(bg='black')
# 윈도우 크기 설정
root.geometry("800x600") # 더 큰 창 크기
app = ChatClientGUI(root)
root.protocol("WM_DELETE_WINDOW", app.on_closing)
root.mainloop()
if __name__ == '__main__':
SECRET_KEY = b'01234567890123456789012345678901'
IV = b'0123456789012345'
main()