-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_appl.py
More file actions
132 lines (105 loc) · 6.06 KB
/
chat_appl.py
File metadata and controls
132 lines (105 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import tkinter as tk
from tkinter import ttk, scrolledtext, messagebox
import socket
import threading
class NetworkChatApp:
def __init__(self, root):
self.root = root
self.root.title("UDP Chat Tool")
self.root.geometry("800x600") # Default size
# Main frame
self.main_frame = ttk.Frame(self.root, padding=10)
self.main_frame.pack(fill=tk.BOTH, expand=True)
# Left side - Chat area
self.chat_frame = ttk.Frame(self.main_frame, padding=10)
self.chat_frame.grid(row=0, column=0, sticky="nsew", padx=10, pady=10)
ttk.Label(self.chat_frame, text="Chat Window", font=("Arial", 14, "bold")).grid(row=0, column=0, sticky="w", pady=5)
self.message_display = scrolledtext.ScrolledText(self.chat_frame, wrap=tk.WORD, font=("Arial", 12))
self.message_display.grid(row=1, column=0, sticky="nsew", padx=5, pady=5)
self.message_display.config(state='disabled')
# Message input
self.input_frame = ttk.Frame(self.chat_frame)
self.input_frame.grid(row=2, column=0, sticky="ew", pady=5)
self.message_entry = ttk.Entry(self.input_frame, font=("Arial", 12))
self.message_entry.grid(row=0, column=0, sticky="ew", padx=5)
self.message_entry.bind("<Return>", self.send_message)
self.send_btn = tk.Button(self.input_frame, text="Send", command=lambda: self.send_message(None), bg="#4CAF50", fg="white",
font=("Arial", 10, "bold"), padx=10, pady=5, relief=tk.RAISED)
self.send_btn.grid(row=0, column=1, padx=5)
self.input_frame.columnconfigure(0, weight=1)
# Right side - Settings & Controls
self.right_panel = ttk.Frame(self.main_frame, padding=10)
self.right_panel.grid(row=0, column=1, sticky="ns", padx=20, pady=10)
ttk.Label(self.right_panel, text="UDP Settings", font=("Arial", 14, "bold")).grid(row=0, column=0, pady=10)
ttk.Label(self.right_panel, text="IP Address:").grid(row=1, column=0, sticky="w", pady=5)
self.ip_entry = ttk.Entry(self.right_panel, font=("Arial", 12))
self.ip_entry.insert(0, "192.168.1.1")
self.ip_entry.grid(row=2, column=0, pady=5)
ttk.Label(self.right_panel, text="Port:").grid(row=3, column=0, sticky="w", pady=5)
self.port_entry = ttk.Entry(self.right_panel, font=("Arial", 12))
self.port_entry.insert(0, "12345")
self.port_entry.grid(row=4, column=0, pady=5)
self.start_btn = tk.Button(self.right_panel, text="Start Chat", command=self.initialize_udp, bg="#008CBA", fg="white",
font=("Arial", 10, "bold"), padx=10, pady=5, relief=tk.RAISED)
self.start_btn.grid(row=5, column=0, pady=10)
# Theme toggle button
self.theme_toggle_btn = tk.Button(self.right_panel, text="Toggle Theme", command=self.toggle_theme, bg="#f39c12", fg="white",
font=("Arial", 10, "bold"), padx=10, pady=5, relief=tk.RAISED)
self.theme_toggle_btn.grid(row=6, column=0, pady=10)
# Zoom In/Out Buttons
self.zoom_in_btn = tk.Button(self.right_panel, text="Zoom In", command=self.zoom_in, bg="#9b59b6", fg="white",
font=("Arial", 10, "bold"), padx=10, pady=5, relief=tk.RAISED)
self.zoom_in_btn.grid(row=7, column=0, pady=10)
self.zoom_out_btn = tk.Button(self.right_panel, text="Zoom Out", command=self.zoom_out, bg="#e74c3c", fg="white",
font=("Arial", 10, "bold"), padx=10, pady=5, relief=tk.RAISED)
self.zoom_out_btn.grid(row=8, column=0, pady=10)
# Status Bar
self.status_label = ttk.Label(self.root, text="Status: Not Connected", anchor="w", font=("Arial", 10))
self.status_label.pack(side=tk.BOTTOM, fill=tk.X)
# Grid layout configuration
self.main_frame.columnconfigure(0, weight=3)
self.main_frame.columnconfigure(1, weight=1)
self.chat_frame.columnconfigure(0, weight=1)
self.chat_frame.rowconfigure(1, weight=1) # Make chat window resizable
# Initialize theme
self.current_theme = "dark"
self.set_theme(self.current_theme)
def set_theme(self, theme):
"""Set the UI theme."""
style = ttk.Style()
if theme == "dark":
style.configure("TFrame", background="#1E1E1E")
style.configure("TLabel", background="#1E1E1E", foreground="white", font=("Arial", 12))
self.message_display.config(bg="#252526", fg="white")
self.status_label.config(background="#333", foreground="white")
else:
style.configure("TFrame", background="#F0F0F0")
style.configure("TLabel", background="#F0F0F0", foreground="black", font=("Arial", 12))
self.message_display.config(bg="#FFFFFF", fg="black")
self.status_label.config(background="#DDD", foreground="black")
def toggle_theme(self):
"""Toggle between light and dark themes."""
self.current_theme = "light" if self.current_theme == "dark" else "dark"
self.set_theme(self.current_theme)
def zoom_in(self):
"""Maximize the window (cross-platform)."""
self.root.attributes("-fullscreen", True) # Works on Windows, macOS, and Linux
def zoom_out(self):
"""Restore the window to normal size."""
self.root.attributes("-fullscreen", False)
self.root.geometry("800x600") # Reset to default size
def initialize_udp(self):
"""Mock function to initialize UDP chat."""
self.status_label.config(text="Status: Chat Started")
def send_message(self, event):
"""Send and display a chat message."""
message = self.message_entry.get().strip()
if message:
self.message_display.config(state='normal')
self.message_display.insert(tk.END, "You: " + message + "\n")
self.message_display.config(state='disabled')
self.message_entry.delete(0, tk.END)
if __name__ == "__main__":
root = tk.Tk()
app = NetworkChatApp(root)
root.mainloop()