Akascape / CTkTable

Customtkinter Table widget (extension/add-on)
MIT License
265 stars 15 forks source link

Not able to fit the CTkTable in CTkScrollableFrame #90

Closed DIY-TECH-HACKER closed 4 months ago

DIY-TECH-HACKER commented 5 months ago

Hi @Akascape I am using CTkTable inside CTkScrollableFrame in horizontal orientation so that I can view the table clearly when the window size is small(When I split the screen with two applications).

The problem is that when I view it when the window is small the CTkTable fits perfectly in CTkScrollableFrame but when the window is in fullscreen there is a massive gap in the frame and it is not filling the frame( pls look at the image below ).

Also having the same issue while using CTkXYFrame

THE CODE 👇👇👇👇👇👇

MySQl_Creadentials_Frame = customtkinter.CTkScrollableFrame(master=Main_Frame, width=690, height=190,corner_radius=10,orientation="horizontal") MySQl_Creadentials_Frame.grid(row= 6,column= 0,padx= (10,0),pady= (0,0),sticky="nsew",columnspan=2) MySQl_Creadentials_Frame.columnconfigure((0),weight=1) MySQl_Creadentials_Frame.rowconfigure((0),weight=1)

with open(Directory+"\\Assets\\MySQL.txt",'r') as MySQL_Details:
    Read_Txt_MySQL = MySQL_Details.readlines()
    for Line in Read_Txt_MySQL:
        Spliter = Line.split()
        Grouper =[Spliter[0]]+[Spliter[1]]
        MySQl_Creadentials_Value += [Grouper]

MySQl_Creadentials_Table = CTkTable(master=MySQl_Creadentials_Frame, row=5, column=2, values=MySQl_Creadentials_Value,header_color=("#42A6FD","#0C4840"),font=("AxaxaxRg-Bold",20))
MySQl_Creadentials_Table.grid(row=0, column=0, sticky="NSEW",columnspan=2,padx=(0,0))

SCREENSHOTS 👇👇👇👇👇

When window is small

image

When window is fullscreen

image

Thanks in advance.........

Akascape commented 4 months ago

@DIY-TECH-HACKER Not a ctktable issue, this behavior is shown with all widgets inside scrollable frame. I know you are expecting it to stretch after full screen, but it is an issue with ctk scrollable frame instead. Try with a button instead, it will show the same behavior.

DIY-TECH-HACKER commented 4 months ago

@Akascape Thank you for the info. But do you know anyway to stretch at full screen I need to view the data in the table when is window size is reduced

Akascape commented 4 months ago

@DIY-TECH-HACKER Ok I will try to find a workaround when the scrollbar reaches full size

DIY-TECH-HACKER commented 4 months ago

@Akascape Thanks a lot

Akascape commented 4 months ago

@DIY-TECH-HACKER Here is an attempt to make dynamic resizing in scrollableframe:


def dynamic_resize(scrollable_frame):
    """ stretch the frame content when it reaches full size """
    scrollable_frame.update()
    original_width = scrollable_frame.winfo_width() 

    def resize_event(event):
        current_width = scrollable_frame._parent_frame.winfo_width() 

        if current_width>original_width:
            scrollable_frame._parent_canvas.itemconfig(scrollable_frame._create_window_id,
                                                       width=current_width)

    scrollable_frame._parent_frame.bind("<Configure>", resize_event, add="+")

scrframe = customtkinter.CTkScrollableFrame(root, orientation="horizontal")
scrframe.pack(expand=True, fill="both")

dynamic_resize(scrframe) # just add this line
...

Let me know if it's working... (also make sure the table/frame content is expandable)

DIY-TECH-HACKER commented 4 months ago

@Akascape It is properly expending with CTkScrollableFrame but the text is cramped when the window size is reduced also getting error while trying to use the function with CTkXYFrame.

This is the error 👇👇👇👇 image

Edit:- I have fixed the text cramping issue

Akascape commented 4 months ago

@DIY-TECH-HACKER It's not for xyframe, because some variable names are different in xyframe.

DIY-TECH-HACKER commented 4 months ago

I tried to create a separate function for CTkXYFrame by replacing the variable name from the function you give with the variable name from CTkXYFrame but got stuck and I don't have enough knowledge to solve the rest of the error.

This is what I could change 👇👇👇

  def Dynamic_Frame_Resizer_CTkXYFrame(Scrollable_Frame):
    Scrollable_Frame.update()
    Original_Width = Scrollable_Frame.winfo_width() 
    def Resize_Event(event):
        Current_Width = Scrollable_Frame.parent_frame.winfo_width() 
        if Current_Width > Original_Width:
            Scrollable_Frame.xy_canvas.itemconfig(Scrollable_Frame._create_window_id,width=Current_Width)

    Scrollable_Frame.parent_frame.bind("<Configure>", Resize_Event, add="+")

And this is the remaining error I got 👇👇👇👇

Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Traceback (most recent call last): File "D:(c drive)\Python\Lib\tkinter__init.py", line 1948, in call return self.func(args) ^^^^^^^^^^^^^^^^ File "d:\INTELLECT 2.0\Intellect 2.0 copy 2.py", line 121, in Resize_Event Scrollable_Frame.xy_canvas.itemconfig(Scrollable_Frame._create_window_id,width=Current_Width) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'CTkXYFrame' object has no attribute '_create_window_id' Exception in Tkinter callback Traceback (most recent call last): File "D:(c drive)\Python\Lib\tkinter__init.py", line 1948, in call__ return self.func(args) ^^^^^^^^^^^^^^^^ File "d:\INTELLECT 2.0\Intellect 2.0 copy 2.py", line 121, in Resize_Event Scrollable_Frame.xy_canvas.itemconfig(Scrollable_Frame._create_window_id,width=Current_Width) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'CTkXYFrame' object has no attribute '_create_window_id' Exception in Tkinter callback Traceback (most recent call last): File "D:(c drive)\Python\Lib\tkinter__init.py", line 1948, in call__ return self.func(*args) ^^^^^^^^^^^^^^^^ File "d:\INTELLECT 2.0\Intellect 2.0 copy 2.py", line 121, in Resize_Event Scrollable_Frame.xy_canvas.itemconfig(Scrollable_Frame._create_window_id,width=Current_Width) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'CTkXYFrame' object has no attribute '_create_window_id' Traceback (most recent call last): File "D:(c drive)\Python\Lib\tkinter\init.py", line 1948, in call__ return self.func(*args) ^^^^^^^^^^^^^^^^ File "D:(c drive)\Python\Lib\site-packages\CTkXYFrame\ctk_xyframe.py", line 40, in self.xy_canvas.configure(yscrollcommand=lambda x,y: self.dynamic_scrollbar_vsb(x,y), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:(c drive)\Python\Lib\site-packages\CTkXYFrame\ctk_xyframe.py", line 81, in dynamic_scrollbar_vsb self.vsb.grid(row=0, column=1, rowspan=2, sticky="nse", pady=5) File "D:(c drive)\Python\Lib\site-packages\customtkinter\windows\widgets\core_widget_classes\ctk_base_class.py", line 321, in grid return super().grid(**self._apply_argument_scaling(kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:(c drive)\Python\Lib\site-packages\customtkinter\windows\widgets\scaling\scaling_base_class.py", line 98, in _apply_argument_scaling scaled_kwargs = copy.copy(kwargs) ^^^^^^^^^^^^^^^^^ File "D:(c drive)\Python\Lib\copy.py", line 76, in copy return copier(x) ^^^^^^^^^ RecursionError: maximum recursion depth exceeded while calling a Python object

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "d:\INTELLECT 2.0\Intellect 2.0 copy 2.py", line 270, in App.mainloop() File "D:(c drive)\Python\Lib\site-packages\customtkinter\windows\ctk_tk.py", line 165, in mainloop super().mainloop(*args, **kwargs) File "D:(c drive)\Python\Lib\tkinter__init.py", line 1485, in mainloop self.tk.mainloop(n) File "D:(c drive)\Python\Lib\tkinter\init.py", line 1952, in call self.widget._report_exception() File "D:(c drive)\Python\Lib\tkinter\init.py", line 1668, in _report_exception root.report_callback_exception(exc, val, tb) File "D:(c drive)\Python\Lib\tkinter\init.py", line 2406, in report_callback_exception traceback.print_exception(exc, val, tb) File "D:(c drive)\Python\Lib\traceback.py", line 124, in print_exception te = TracebackException(type(value), value, tb, limit=limit, compact=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:(c drive)\Python\Lib\traceback.py", line 687, in init__ _seen.add(id(exc_value)) ^^^^^^^^^^^^^ RecursionError: maximum recursion depth exceeded while calling a Python object

Akascape commented 4 months ago

@DIY-TECH-HACKER There was a thing missing in xyframe, I added it now. update and test this:

def dynamic_resize(xy_frame):
    """ stretch the frame content when it reaches full size """
    xy_frame.update()
    original_width = xy_frame.winfo_width() 

    def resize_event(event):
        current_width = xy_frame.parent_frame.winfo_width() 

        if current_width>original_width:
            xy_frame.xy_canvas.itemconfig(xy_frame.window_id, width=current_width)

    xy_frame.parent_frame.bind("<Configure>", resize_event, add="+")
...

dynamic_resize(xy_frame)
DIY-TECH-HACKER commented 4 months ago

Still getting error after updating and using the given function

Error 👇👇👇👇👇 Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Exception in Tkinter callback Traceback (most recent call last): File "D:(c drive)\Python\Lib\tkinter__init.py", line 1948, in call__ return self.func(*args) ^^^^^^^^^^^^^^^^ File "D:(c drive)\Python\Lib\site-packages\CTkXYFrame\ctk_xyframe.py", line 40, in self.xy_canvas.configure(yscrollcommand=lambda x,y: self.dynamic_scrollbar_vsb(x,y), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:(c drive)\Python\Lib\site-packages\CTkXYFrame\ctk_xyframe.py", line 81, in dynamic_scrollbar_vsb self.vsb.grid(row=0, column=1, rowspan=2, sticky="nse", pady=5) File "D:(c drive)\Python\Lib\site-packages\customtkinter\windows\widgets\core_widget_classes\ctk_base_class.py", line 321, in grid return super().grid(**self._apply_argument_scaling(kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:(c drive)\Python\Lib\site-packages\customtkinter\windows\widgets\scaling\scaling_base_class.py", line 98, in _apply_argument_scaling scaled_kwargs = copy.copy(kwargs) ^^^^^^^^^^^^^^^^^ File "D:(c drive)\Python\Lib\copy.py", line 76, in copy return copier(x) ^^^^^^^^^ RecursionError: maximum recursion depth exceeded while calling a Python object

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "d:\INTELLECT 2.0\Intellect 2.0 copy 2.py", line 283, in App.mainloop() File "D:(c drive)\Python\Lib\site-packages\customtkinter\windows\ctk_tk.py", line 165, in mainloop super().mainloop(*args, **kwargs) File "D:(c drive)\Python\Lib\tkinter__init.py", line 1485, in mainloop self.tk.mainloop(n) File "D:(c drive)\Python\Lib\tkinter\init.py", line 1952, in call self.widget._report_exception() File "D:(c drive)\Python\Lib\tkinter\init.py", line 1668, in _report_exception root.report_callback_exception(exc, val, tb) File "D:(c drive)\Python\Lib\tkinter\init.py", line 2406, in report_callback_exception traceback.print_exception(exc, val, tb) File "D:(c drive)\Python\Lib\traceback.py", line 124, in print_exception te = TracebackException(type(value), value, tb, limit=limit, compact=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:(c drive)\Python\Lib\traceback.py", line 687, in init__ _seen.add(id(exc_value)) ^^^^^^^^^^^^^ RecursionError: maximum recursion depth exceeded while calling a Python object

Akascape commented 4 months ago

@DIY-TECH-HACKER Try to specify height and width in xyframe, maybe increase the height/width. This is actually a bug I found.

DIY-TECH-HACKER commented 4 months ago

I increased the height and width now it is working perfectly

Thanks for your help......