Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: CTkEntry.xview() takes 2 positional arguments but 3 were given #2356

Open
norpba opened this issue Apr 4, 2024 · 3 comments
Open

Comments

@norpba
Copy link

norpba commented Apr 4, 2024

Hi,

I don't know if I'm doing something wrong, but I'm trying to create an entry box and add a scrollbar into it if the string is longer than the widget is wide, so that the user can scroll the string. I've been trying to google this problem (and ask chatgpt) for three days now and to no avail. If you'd like to reproduce the "bug" or my mistake (if it is that), then you can clone my PyARR repo.

Code snippet from my project:

    def __init__(self, master, *args, **kwargs):
        super().__init__(master, *args, **kwargs)
        
        self.source_entry = customtkinter.CTkEntry(self, placeholder_text=("test"*100))
        self.source_entry.grid(row=0, column=0, padx=10, pady=10, sticky="nwe")
        
        self.scrollbar = customtkinter.CTkScrollbar(self, orientation="horizontal", command=self.source_entry.xview)
        self.scrollbar.grid(row=1, column=0, padx=10, pady=10, sticky="nwe")

        self.source_entry.configure(xscrollcommand=self.scrollbar.set)
@norpba
Copy link
Author

norpba commented Apr 4, 2024

I don't know how I managed to mess up trying to code snippet this, sorry...

# isolating the problem

import customtkinter

app = customtkinter.CTk()

entry = customtkinter.CTkEntry(app, placeholder_text=("testi"*500))
entry.grid(row=0, column=0, pady=20)

scrollbar = customtkinter.CTkScrollbar(app, orientation="horizontal", command=entry.xview)
scrollbar.grid(row=1, column=0)

entry.configure(xscrollcommand=scrollbar.set)
app.mainloop() 

@norpba
Copy link
Author

norpba commented Apr 4, 2024

and finally, a "fix" that my friend wrote, but I won't write something like that in my project. I'll just switch back to using a label or a textbox if I'm doing this somehow wrong. Thanks in advance.

class SourcePathFrame(customtkinter.CTkFrame): 
    def __init__(self, master, *args, **kwargs):
        super().__init__(master, *args, **kwargs)
        
        def on_scroll(*args):
            print("Scrollbar command:", args)
            # Only pass the second argument (position) to xview_moveto
            if args[0] == 'moveto':
                self.source_entry.xview_moveto(args[1])
            else:  # handle 'scroll' if needed
                print("Scroll action not handled")

        self.source_stringvar = StringVar()
        self.scrollbar = customtkinter.CTkScrollbar(self, orientation="horizontal", command=on_scroll)
        self.scrollbar.grid(row=1, column=0, padx=10, pady=10, sticky="nwe")
        
        self.source_entry = customtkinter.CTkEntry(self, xscrollcommand=self.scrollbar.set)
        self.source_entry.grid(row=0, column=0, padx=10, pady=10, sticky="nwe")
        
        # Now the scrollbar's command is linked to the on_scroll function
        self.scrollbar.configure(command=on_scroll)
        
        self.path_string = "/path/to/your/long/file/path/here/very_long_path_name.txt"
        self.source_entry.insert(0, self.path_string)

@Amisoo
Copy link

Amisoo commented Apr 10, 2024

Hello sorry for not finding a direct solution, however I found that the Entry label from tkinter works with a scrollbar entry = tkinter.Entry(app). I also found that the customtkinter Textbox have a scroll bar by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants