error %Run mpremotegui.py Traceback (most recent call last): File "G:\My…
- User
error
%Run mpremote_gui.py Traceback (most recent call last): File "G:\My Drive\python\mpremote_gui.py", line 127, in file_listbox = ctk.CTkListbox(app, height=200, noheadings=False, selectmode="single") # Use CtkListbox for selection AttributeError: module 'customtkinter' has no attribute 'CTkListbox'
running this code import subprocess import tkinter import customtkinter as ctk from tkinter import messagebox, filedialog import os import re # Importing regex for stripping leading numbers
def list_files(): try: # Run the mpremote command to list files on the Pico result = subprocess.run( ["mpremote", "fs", "ls"], capture_output=True, text=True, check=True )
print("Command executed successfully") # Debugging output # Clear current listbox file_listbox.delete(0, "end") # Clear the display in the listbox # Insert the result into the listbox, removing leading numbers for line in result.stdout.strip().split('\n'): file_name = line.strip() # Strip leading numbers and spaces cleaned_name = re.sub(r'^\d+\s*', '', file_name) # Remove leading numbers and spaces file_listbox.insert("end", cleaned_name) # Insert the cleaned name into the listbox except subprocess.CalledProcessError as e: error_message = f"Failed to list files:\n" error_message += f"Return Code: {e.returncode}\n" error_message += f"STDOUT: {e.stdout}\n" error_message += f"STDERR: {e.stderr}" messagebox.showerror("Error", error_message) except Exception as e: messagebox.showerror("Error", f"An unexpected error occurred: {str(e)}")def upload_file(): # Open a file dialog to select a file file_path = filedialog.askopenfilename() if file_path: file_name = os.path.basename(file_path)
print(f"Uploading '{file_path}' to Pico as '/{file_name}'") if not os.path.exists(file_path): messagebox.showerror("Error", f"The file does not exist at: {file_path}") return try: # Run mpremote cp to upload the selected file to the Pico command = ["mpremote", "fs", "cp", file_path, f":/{file_name}"] print(f"Executing command: {' '.join(command)}") result = subprocess.run( command, capture_output=True, text=True, check=True ) messagebox.showinfo("Success", f"Uploaded '{file_name}' to Pico successfully!") list_files() # Refresh the file list after uploading except subprocess.CalledProcessError as e: error_message = f"Failed to upload file:\n" error_message += f"Return Code: {e.returncode}\n" error_message += f"STDOUT: {e.stdout}\n" error_message += f"STDERR: {e.stderr}" messagebox.showerror("Error", error_message)def view_file_contents(event): try: # Get the selected file from the listbox selected_file = file_listbox.get(file_listbox.curselection())
- Assistant
The error message you're encountering,
AttributeError: module 'customtkinter' has no attribute 'CTkListbox', indicates that theCTkListboxclass is not recognized in thecustomtkintermodule you are using. This could be due to one of the following reasons:-
Version Issue: The
CTkListboxmight not be part of the version ofcustomtkinterthat you have installed. You can check the version ofcustomtkinterby running the following command in Python:
-
- User
- Assistant
- User
look at this page https://github.com/Akascape/CTkListbox/blob/main/README.md
- Assistant
- User
now works perfectly thank you
- Assistant
You're welcome! I'm glad to hear that everything is working perfectly for you now. If you have any more questions or if there's anything else you need assistance with, feel free to ask. Happy coding!
- User
please add the option to Delete a file
- Assistant
- User
perfect. what other functions would you suggest to round the app out
- Assistant
- User
great answer. lests start with the light and dark options please
- Assistant
- User
full code please
- Assistant
- User
dark light switching works well but, there is a large verticle space surrounding the theme switch
- Assistant
- User
still the same, about half of the verticle area of the app surrounds the theme button
- Assistant
- User
theme button problem is now sorted but, the file contents area does not fill out to the rhs of the app
- Assistant
- User
fixed. now can we add 2. Download File Functionality: Enable the user to download files from the Pico to their local machine. Implementation: Use the mpremote fs pull command to retrieve files from the Pico.
- Assistant
- User
perfect works well, lets do this one now
- Rename File Functionality: Allow users to rename files directly from the application. Implementation: Prompt the user for a new name and then use the mpremote fs mv command to rename the file.
- Assistant
- User
goes through all the actions Command executed successfully Executing command: mpremote fs mv :start_up.py :2_start_up.py Command executed successfully but the file is not renamed
- Assistant
- User
still the same Executing command: mpremote fs mv :start_up.py :2_start_up.py Command executed successfully
- Assistant
- User
ok looking at the docs for mpremote, file renaming is not an option see https://docs.micropython.org/en/latest/reference/mpremote.html#mpremote-command-fs
- Assistant
- User
- Assistant
- User
can this not be done directly in the text area without the need to download and upload the file
- Assistant
- User
still get the file dialogue?
- Assistant
- User
edits are lost
- Assistant
- User
works. but the Save Changes button should only be shown when in edit mode
- Assistant
- User
great, there was an error, needed to change save_button.config(command=save_changes) to save_button.configure(command=save_changes)
- Assistant
- User
can we add a notice to the right of the theme button when in edit mode
- Assistant
- User
no edit mode indicator shown and error Failed to upload changes code 1
- Assistant
- User
still the same. please note that editing was working before adding an edit indicator
- Assistant
- User
save edit still failing Selected file: 'start_up.py' Executing command: mpremote fs cat :start_up.py Editing file: 'start_up.py' Executing command: mpremote fs cat :start_up.py Saving changes to 'start_up.py' cp - :start_up.py mpremote: cp: 2: No such file or directory.
- Assistant
- User
now working. can we add a cancel editing putton as well
- Assistant
- User
error cancel button refered to before assignment
- Assistant
- User
same error
- Assistant
- User
- Assistant
- User
ok fixed by removing extra
Create the Cancel Editing button, ensuring it's defined at the right time
cancel_button = ctk.CTkButton(app, text="Cancel Editing", command=cancel_editing) # Create cancel button cancel_button.grid(row=2, column=0, padx=10, pady=10, sticky='se') # Initial placementwhich was here
def cancel_editing(): text_area.delete("1.0", ctk.END) # Clear the text area save_button.grid_forget() # Hide the save button cancel_button.grid_forget() # Hide the cancel button edit_mode_label.configure(text="") # Clear edit mode label global is_editing is_editing = False # Reset editing mode
# Create the Cancel Editing button, ensuring it's defined at the right time cancel_button = ctk.CTkButton(app, text="Cancel Editing", command=cancel_editing) # Create cancel button cancel_button.grid(row=2, column=0, padx=10, pady=10, sticky='se') # Initial placement - Assistant