Untitled

 avatar
unknown
plain_text
5 months ago
5.0 kB
3
Indexable
class WifiConfiguratorApp(ctk.CTk):
    def __init__(self):
        super().__init__()
        self.title("Wi-Fi Configurator")
        self.geometry("1024x600")
        self.resizable(False, False)
        
        # Variables
        self.networks = []
        self.selected_network = StringVar()
        self.password = StringVar()
        self.show_password = ctk.BooleanVar(value=False)
        self.keyboard_visible = False
        self.current_connection = {
            "SSID": "Not connected",
            "Signal Strength": "N/A",
            "IP Address": "N/A"
        }
        self.status_message = StringVar(value="Idle")
        
        # Create main container
        self.main_container = ctk.CTkFrame(self)
        self.main_container.pack(fill="both", expand=True)
        
        # Create UI Elements
        self.create_widgets()
        self.scan_wifi_networks()
        self.update_current_connection()

    def create_widgets(self):
        # Top section (always visible)
        self.top_frame = ctk.CTkFrame(self.main_container)
        self.top_frame.pack(fill="x", padx=20, pady=(10, 0))  # Reduced bottom padding

        # Title and Status
        title_label = ctk.CTkLabel(
            self.top_frame, 
            text="Wi-Fi Configurator",
            font=("Arial", 28, "bold")  # Slightly smaller font
        )
        title_label.pack(pady=(5, 0))  # Reduced padding

        self.status_label = ctk.CTkLabel(
            self.top_frame,
            textvariable=self.status_message,
            font=("Arial", 14)  # Slightly smaller font
        )
        self.status_label.pack(pady=(0, 5))  # Reduced padding

        # Content section
        self.content_frame = ctk.CTkFrame(self.main_container)
        self.content_frame.pack(fill="both", expand=True, padx=20)

        # Network selection
        network_label = ctk.CTkLabel(
            self.content_frame,
            text="Select Network:",
            font=("Arial", 14)
        )
        network_label.pack(pady=(10, 0))  # Reduced padding

        self.network_dropdown = ctk.CTkOptionMenu(
            self.content_frame,
            variable=self.selected_network,
            values=self.networks,
            width=250,  # Slightly smaller width
            height=35   # Slightly smaller height
        )
        self.network_dropdown.pack(pady=(0, 5))  # Reduced padding

        # Password entry
        password_label = ctk.CTkLabel(
            self.content_frame,
            text="Password:",
            font=("Arial", 14)
        )
        password_label.pack(pady=(5, 0))  # Reduced padding

        self.password_entry = ctk.CTkEntry(
            self.content_frame,
            textvariable=self.password,
            show="*",
            width=250,  # Slightly smaller width
            height=35   # Slightly smaller height
        )
        self.password_entry.pack(pady=(0, 5))  # Reduced padding
        self.password_entry.bind("<FocusIn>", self.show_keyboard)

        # Action buttons in horizontal layout
        button_frame = ctk.CTkFrame(self.content_frame)
        button_frame.pack(pady=(5, 10))  # Reduced padding

        ctk.CTkButton(
            button_frame,
            text="Connect",
            command=self.start_connecting_to_wifi,
            width=100,   # Slightly smaller width
            height=35    # Slightly smaller height
        ).grid(row=0, column=0, padx=5)

        ctk.CTkButton(
            button_frame,
            text="Refresh",
            command=self.scan_wifi_networks,
            width=100,   # Slightly smaller width
            height=35    # Slightly smaller height
        ).grid(row=0, column=1, padx=5)

        # Connection info (collapsible) - Made more compact
        self.connection_frame = ctk.CTkFrame(self.content_frame)
        self.connection_frame.pack(fill="x", pady=(0, 10))  # Reduced padding

        self.ssid_label = ctk.CTkLabel(
            self.connection_frame,
            text="SSID: Not connected",
            font=("Arial", 12)  # Smaller font
        )
        self.ssid_label.pack(pady=1)

        self.signal_label = ctk.CTkLabel(
            self.connection_frame,
            text="Signal Strength: N/A",
            font=("Arial", 12)  # Smaller font
        )
        self.signal_label.pack(pady=1)

        self.ip_label = ctk.CTkLabel(
            self.connection_frame,
            text="IP Address: N/A",
            font=("Arial", 12)  # Smaller font
        )
        self.ip_label.pack(pady=1)

        # Keyboard container (hidden initially)
        self.keyboard_frame = ctk.CTkFrame(self.main_container)
        self.keyboard = TouchKeyboard(
            self.keyboard_frame,
            self.password_entry,
            self.hide_keyboard,
            fg_color="transparent"
        )
        self.keyboard.pack(pady=(0, 10))  # Adjusted padding
Editor is loading...
Leave a Comment