Untitled
unknown
plain_text
5 months ago
8.3 kB
4
Indexable
import customtkinter as ctk import subprocess import threading from tkinter import StringVar class CustomKeyboard(ctk.CTkFrame): def __init__(self, master, password_var, on_connect, **kwargs): super().__init__(master, **kwargs) self.password_var = password_var self.on_connect = on_connect self.shift_mode = False # Keyboard layouts self.normal_layout = [ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'], ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'], ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'], ['⇧', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '⌫'], ['!@#', 'Space', '✓'] ] self.shift_layout = [ ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')'], ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'], ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'], ['⇧', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '⌫'], ['123', 'Space', '✓'] ] self.special_layout = [ ['~', '`', '"', '\'', '+', '-', '_', '=', '\\', '|'], ['{', '}', '[', ']', '<', '>', ':', ';', '/', '?'], ['!', '@', '#', '$', '%', '^', '&', '*'], ['⇧', '(', ')', ',', '.', '€', '£', '⌫'], ['ABC', 'Space', '✓'] ] self.current_layout = self.normal_layout self.create_keyboard() def create_keyboard(self): # Clear existing widgets for widget in self.winfo_children(): widget.destroy() # Configure grid weights self.grid_columnconfigure(tuple(range(10)), weight=1) # Create buttons with new modern style for row_idx, row in enumerate(self.current_layout): for col_idx, key in enumerate(row): btn_width = 65 # Default button width col_span = 1 if key == 'Space': btn_width = 400 col_span = 6 elif key in ['!@#', '123', 'ABC']: btn_width = 100 col_span = 2 elif key == '✓': btn_width = 100 col_span = 2 fg_color = "#2ecc71" # Green color for connect button else: btn_width = 65 button = ctk.CTkButton( self, text=key, width=btn_width, height=60, font=("Arial Bold", 20), fg_color="#333333" if key not in ['✓', '⇧', '!@#', '123', 'ABC'] else "#2ecc71" if key == '✓' else "#1a1a1a", command=lambda k=key: self.key_press(k) ) # Calculate grid position if row_idx == 2: # Center the shorter rows button.grid(row=row_idx, column=col_idx + 1, columnspan=col_span, padx=2, pady=2) elif row_idx == 3: button.grid(row=row_idx, column=col_idx + 1, columnspan=col_span, padx=2, pady=2) else: button.grid(row=row_idx, column=col_idx, columnspan=col_span, padx=2, pady=2) def key_press(self, key): current_text = self.password_var.get() if key == '⌫': self.password_var.set(current_text[:-1]) elif key == 'Space': self.password_var.set(current_text + ' ') elif key == '⇧': self.shift_mode = not self.shift_mode self.current_layout = self.shift_layout if self.shift_mode else self.normal_layout self.create_keyboard() elif key in ['!@#', '123']: self.current_layout = self.special_layout self.create_keyboard() elif key == 'ABC': self.current_layout = self.normal_layout self.create_keyboard() elif key == '✓': self.on_connect() else: self.password_var.set(current_text + key) class WifiConfiguratorApp(ctk.CTk): def __init__(self): super().__init__() self.title("Wi-Fi Configurator") self.geometry("1024x600") self.resizable(False, False) self.networks = [] self.selected_network = StringVar() self.password = StringVar() self.show_password = ctk.BooleanVar(value=False) self.current_connection = { "SSID": "Not connected", "Signal Strength": "N/A", "IP Address": "N/A" } self.status_message = StringVar(value="Idle") self.create_widgets() self.scan_wifi_networks() self.update_current_connection() def create_widgets(self): # Main container main_container = ctk.CTkFrame(self) main_container.pack(fill="both", expand=True) # Left panel (30% of width) left_panel = ctk.CTkFrame(main_container, width=300) left_panel.pack(side="left", fill="y", padx=10, pady=10) # Title title_label = ctk.CTkLabel(left_panel, text="Wi-Fi Setup", font=("Arial", 28, "bold")) title_label.pack(pady=10) # Status self.status_label = ctk.CTkLabel(left_panel, textvariable=self.status_message, font=("Arial", 14), text_color="green") self.status_label.pack(pady=5) # Current Connection Frame conn_frame = ctk.CTkFrame(left_panel) conn_frame.pack(fill="x", pady=10) ctk.CTkLabel(conn_frame, text="Current Connection", font=("Arial", 18, "bold")).pack(pady=5) self.ssid_label = ctk.CTkLabel(conn_frame, text="SSID: Not connected") self.ssid_label.pack(pady=2) self.signal_label = ctk.CTkLabel(conn_frame, text="Signal Strength: N/A") self.signal_label.pack(pady=2) self.ip_label = ctk.CTkLabel(conn_frame, text="IP Address: N/A") self.ip_label.pack(pady=2) # Network Selection ctk.CTkLabel(left_panel, text="Select Network:", font=("Arial", 16)).pack(pady=(20,5)) self.network_dropdown = ctk.CTkOptionMenu(left_panel, variable=self.selected_network, values=self.networks, width=200) self.network_dropdown.pack(pady=5) # Password Field ctk.CTkLabel(left_panel, text="Password:", font=("Arial", 16)).pack(pady=(20,5)) self.password_entry = ctk.CTkEntry(left_panel, textvariable=self.password, show="*", width=200) self.password_entry.pack(pady=5) # Refresh button refresh_btn = ctk.CTkButton(left_panel, text="Refresh Networks", command=self.scan_wifi_networks) refresh_btn.pack(pady=20) # Right panel (70% of width) - Keyboard keyboard_frame = ctk.CTkFrame(main_container) keyboard_frame.pack(side="right", fill="both", expand=True, padx=10, pady=10) self.keyboard = CustomKeyboard(keyboard_frame, self.password, self.start_connecting_to_wifi) self.keyboard.pack(pady=10) # [Previous methods remain unchanged: scan_wifi_networks, start_connecting_to_wifi, # connect_to_wifi, update_current_connection, toggle_password_visibility, # reset_password, close_app] if __name__ == "__main__": ctk.set_appearance_mode("Dark") ctk.set_default_color_theme("blue") app = WifiConfiguratorApp() app.mainloop()
Editor is loading...
Leave a Comment