CustomTkinter
CustomTkinter copied to clipboard
Textbox + Tab View Leads to Errors
Adding a textbox to a tab view leads to AttributeError: 'CTkTextbox' object has no attribute '_x_scrollbar'
.
Minimal example:
import customtkinter as ctk
def create_tab_view(parent):
tv = ctk.CTkTabview(parent, height=0)
tv.grid(sticky="nsew")
tv.add("A")
txt1 = ctk.CTkTextbox(tv.tab("A"))
txt1.grid(sticky="WE", padx=10, pady=0)
class main(ctk.CTk):
def __init__(self, parent=None):
super().__init__(parent)
btn = ctk.CTkButton(self, text="test")
btn.grid(row=0, column=0, sticky="nsew")
btn.configure(command=lambda: create_tab_view(self))
if __name__ == "__main__":
root = main()
root.mainloop()
Then just click the button.
In the __init__
of the CTKTextbox class, during the creation of the self._y_scrollbar
, it calls self._canvas.update_idletasks()
which for some reason ends up looking for the _x_scrollbar
as well... which wasn't made yet.
Hi @Wyko, try this. It worked for me:
import customtkinter as ctk
def create_tab_view(parent):
# create the tabview
tv = ctk.CTkTabview(master=parent, height=0)
tv.grid(sticky="nsew", row = 1, column = 0)
# add new tab
utils_frame =tv.add("A")
# create a fictitious frame inside the tab
frame = ctk.CTkFrame(master=utils_frame)
frame.pack(expand = True, fill = ctk.BOTH)
# insert textbox inside fictitious frame
txt1 = ctk.CTkTextbox(frame, width=400, corner_radius=0)
txt1.grid(row = 0, column = 0, sticky="WE", padx=10, pady=0)
# main class
class main(ctk.CTk):
def __init__(self, parent=None):
super().__init__(parent)
self.rowconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
self.columnconfigure(0, weight=1)
btn = ctk.CTkButton(self, text="test")
btn.grid(row=0, column=0, sticky="nsew")
btn.configure(command=lambda: create_tab_view(self))
if __name__ == "__main__":
root = main()
root.mainloop()
Workss fine on macOS, I will tets it on Windows.