Open norpba opened 3 months ago
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()
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)
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.
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: