Problems with CustomTkinter Scrollable frame

`import customtkinter as ctk
from info import IP, PORT, logo_path
from PIL import Image, ImageTk
from datetime import datetime

class Menu(ctk.CTk):
def init(self):
super().init()
self.title(“Y – Artificial Intelligence”)
self.resizable(False, False)
self.configure_window()
self._set_appearance_mode(“dark”)
self.wm_iconbitmap(logo_path)
self.SendMessageEnabled = True
self.username = “”
self.age = 0
self.openai_api_key = “”

def UpdateInfo(self, username, age, openai_api_key):
    self.username = username
    self.age = age
    self.openai_api_key = openai_api_key    
    print(f"Username: {self.username}, Age: {self.age}, OpenAI API Key: {self.openai_api_key}")


def configure_window(self):
    # Get the screen width and height
    screen_width = self.winfo_screenwidth()
    screen_height = self.winfo_screenheight()

    # Set the geometry of the window to fullscreen
    self.geometry("{0}x{1}+0+0".format(screen_width, screen_height))
    self.create_text_box()

def create_text_box(self):
    # Create a custom font
    custom_font = ctk.CTkFont(family="Century Gothic", size=16, weight="bold")

    # Create the text box
    self.text_box = ctk.CTkTextbox(
        self,
        border_color="#818181",
        border_width=1.5,
        font=custom_font,
        fg_color="#242525",
        border_spacing=5,
        width=1200,
        height=10,  # Adjust height as needed
        wrap="char",  # Wrap text at word boundaries
        scrollbar_button_color="#000000",
    )
    self.text_box.pack(padx=90, pady=(0, 20), side="bottom", anchor="se")
    self.text_box.insert("1.0", "Message Y...")  # Insert placeholder text
    self.text_box.configure(text_color="#818181")  # Change text color to placeholder color
    self.text_box.bind("<FocusIn>", self.on_textbox_focus)
    self.text_box.bind("<Key>", self.on_key_pressed)
    self.text_box.bind("<Return>", self.on_enter_pressed)  # Bind Enter key event

    # Create the scrollable frame
    self.scroll_frame = ctk.CTkScrollableFrame(
        self,
        scrollbar_button_color="black",  # Set the scrollbar color to black
        width=1180,  # Adjust width as needed
        height=1000,  # Adjust height as needed
        fg_color="transparent"  # Set background color to transparent
    )
    self.scroll_frame.pack(padx=(250,80), pady=(10, 10))
    self.username="Y - AI"
    self.put_message(f'Hello, {self.username}! I am Y, your personal AI assistant. How can I assist you today?')



def on_textbox_focus(self, event):
        # Check if textbox is empty
        if self.text_box.get("1.0", "end-1c") == "":
            self.text_box.insert("1.0", "Message Y...")  # Insert placeholder text
            self.text_box.configure(text_color="#818181")  # Change text color to placeholder color
def on_key_pressed(self, event):
    # Check if the placeholder text is present when a key is pressed
    if self.text_box.get("1.0", "end-1c") == "Message Y...":
        self.text_box.delete("1.0", "end")  # Remove placeholder text
        self.text_box.configure(text_color="white")  # Change text color to white

    # Get the current text in the text box
    text = self.text_box.get("1.0", "end-1c")

    # Calculate the number of lines based on the number of characters
    num_chars = len(text)
    line_height = 25  # Adjust this value as needed
    max_char_per_line = 111  # Maximum characters per line
    # Manual switch statements to adjust the number of lines
    if num_chars <= max_char_per_line:
        num_lines = 1
    elif max_char_per_line < num_chars <= max_char_per_line*2:
        num_lines = 2
    elif max_char_per_line*2 < num_chars <= max_char_per_line*3:
        num_lines = 3
    elif max_char_per_line*3 < num_chars <= max_char_per_line*4:
        num_lines = 4
    else:
        num_lines = 5

    # Calculate the new height of the text box based on the number of lines
    max_height = 20  # Maximum number of lines
    new_height = min(num_lines, max_height) * line_height

    # Adjust the height of the text box
    self.text_box.configure(height=new_height)

# Eneter pressed
def on_enter_pressed(self, event):
    if self.SendMessageEnabled:
        self.SendMessageEnabled = True # Change Value
        # Print the text when Enter key is pressed
        text = self.text_box.get("1.0", "end-1c")
        self.text_box.delete(0.0, "end")
        self.text_box.mark_set("insert", "1.0")
        self.text_box.configure(height=20) 
        self.put_message(text)
        self.scroll_frame.set(1.0,1.0)

    
def put_message(self, message):
    # Get the current time
    current_time = datetime.now().strftime("%H:%M:%S")

    # Format the message to display including username and timestamp
    message_text = f"{self.username} {' ' * (20 - len(self.username))} {current_time}n"

    # Limit the length of each line of the message
    max_line_length = 60
    for i in range(0, len(message), max_line_length):
        message_text += message[i:i+max_line_length] + "n"

    # Create the message label inside the scrollable frame's inner frame
    message_label = ctk.CTkLabel(
        self.scroll_frame,
        text=message_text,
        fg_color="transparent",
        font=ctk.CTkFont(family="Century Gothic", size=16),
        justify="left"
    )
    message_label.pack(pady=(0, 5), side="top", anchor="sw")`

In on_enter_pressed, I want the frame to scroll to the end. How do I do that?

I tried to use self.scroll_frame._scrollbar.set(1.0, 1.0), but it didnt work.

New contributor

Movies Trailers is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật