[Feature Requrest] Textbox auto-resizing argument when creating
Like:
textbox = customtkinter.CtkTextbox(app, autoresize=True)
What do you mean with autoresize, what do you want to achieve?
Perhaps, rather than the textbox being stuck at a width and height, you can give a maximum width and height. From there, the textbox will resize itself to only fit the text inside of it. Basically, you would eliminate the extra, empty space below the text. If the text was too little for the textbox that was too big.
If that made any sense?? Sorry - it was confusing I know
Anyone got solution for this?
@ahad-naseer-innusagi - Use a customtkinter.StringVar to check the length of the string inside the textbox. Then, calculate the width of the textbox (maybe using data about the font's width per character in pixels or something?) and resize the textbox's width with customtkinter.CTkTextbox.configure(). Make sure to set the redraw parameter as True.
@dishb- I have tried calculating text width and determine the textbox height parameter by multiplying lines count with height, the issue sometimes it work perfect for medium length text but when text is long it leaves empty spaces below and if text is short it will set height too short and I have to scroll to see the text.
@ahad-naseer-innusagi - I don't think there is much of a solution then. I haven't used CTk in a while... Not to mention, with this current hack, your application's performance will take a hit.
Temporary, I have created a solution in which i check if scrollbar is shown then 1 Px is incremented in height. It effects the performance a little bit. UI looks good so i am using it.
I am looking for the same feature. What I think OP is trying to do is create a box that dynamically changes its height based on it's width. In standard Tkinter this was easy:
class ChatBubble(tk.Frame):
def __init__(self, master, sender, message, bg_color):
super().__init__(master)
self.text_widget = tk.Text(self, wrap='word', bg=bg_color, font=('Helvetica', 10), borderwidth=2,
relief="solid", width=50)
self.text_widget.insert(tk.END, message)
self.text_widget.grid(row=0, column=0, sticky="ew")
self.columnconfigure(0, weight=1)
self.text_widget.bind("<Configure>", self.on_configure)
def on_configure(self, event):
"""Dynamically set the height of the text widget based on its width."""
lines = self.text_widget.count("1.0", "end", "displaylines")[0]
self.text_widget.config(height=lines)
def set_state(self, state):
self.text_widget.configure(state=state)