Untitled
unknown
plain_text
5 months ago
2.2 kB
3
Indexable
], 'special': [ ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')'], ['-', '_', '=', '+', '[', ']', '{', '}', '\\', '|'], ['/', ':', ';', '"', '\'', ',', '.', '?', '<', '>'], ['ABC', '~', '`', '€', '£', '¥', '§', '⌫'], ['123', ' ', '⌨'] ] } self.current_layout = 'default' self.create_keyboard() def create_keyboard(self): # Clear existing buttons for widget in self.winfo_children(): widget.destroy() # Create keyboard layout layout = self.layouts[self.current_layout] for row_idx, row in enumerate(layout): row_frame = ctk.CTkFrame(self, fg_color="transparent") row_frame.grid(row=row_idx, column=0, pady=2) for col_idx, key in enumerate(row): # Determine button width based on key width = 65 if key not in ['⌫', '⇧', '#+=', 'ABC', '123', ' ', '⌨'] else 90 if key == ' ': width = 300 btn = ctk.CTkButton( row_frame, text=key, width=width, height=50, command=lambda k=key: self.key_press(k) ) btn.grid(row=0, column=col_idx, padx=2) def key_press(self, key): if key == '⌫': current = self.entry.get() self.entry.delete(0, 'end') self.entry.insert(0, current[:-1]) elif key == '⇧': self.current_layout = 'default' if self.current_layout == 'shift' else 'shift' self.create_keyboard() elif key == '#+=': self.current_layout = 'special' self.create_keyboard() elif key == 'ABC' or key == '123': self.current_layout = 'default' self.create_keyboard() elif key == '⌨': self.hide_callback() else: current_pos = self.entry.index('insert') self.entry.insert(current_pos, key)
Editor is loading...
Leave a Comment