TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
11.52k stars 1.08k forks source link

Need for hereditary feature that was in classic tkinter. The Treeview #1680

Closed emircetinmemis closed 1 year ago

emircetinmemis commented 1 year ago

Hi, I have been searching about UI frameworks for tkinter, and found out the most accurate one was customtkinter for me. I was about to turn my application to customtkinter, but I realized that I'm facing with a problem on a specific widget. My application uses several tables or lists on displaying purposes. So with this, I must be able to use a widget like Treeview which comes from the culture of tkinker.

An example of a basic execution;
from    tkinter         import ttk
import  customtkinter   as ctk
import  tkinter         as tk

class WithNormalTk(tk.Tk) :

  def __init__(self, *args, **kwargs) :
    super().__init__(*args, **kwargs)

    treeview = ttk.Treeview(self, height=4, show="headings", selectmode="browse")
    treeview.pack(side="top", fill="both", expand=True)

    treeview["columns"] = ("one", "two", "three")

    treeview.heading("one", text="Column A")
    treeview.heading("two", text="Column B")
    treeview.heading("three", text="Column C")

    treeview.column("one", width=100)
    treeview.column("two", width=100)
    treeview.column("three", width=100)

    treeview.insert("", "end", values=("1", "2", "3"))
    treeview.insert("", "end", values=("4", "5", "6"))
    treeview.insert("", "end", values=("7", "8", "9"))

class WithCustomTk(ctk.CTk) :

  def __init__(self, *args, **kwargs) :
    super().__init__(*args, **kwargs)

    # TODO: Find a way out.

if __name__ == "__main__" :

  app = WithNormalTk()
  app.mainloop()

  app = WithCustomTk()
  app.mainloop()
And this shortly results as;

1 2

What I have tried to do;
The solution;
emircetinmemis commented 1 year ago

I forgat too add this.

For the "What I have tried to do;" part,

TomSchimansky commented 1 year ago

You can still use a tkinter treevieew in CustomTkinter:

from tkinter import ttk
import customtkinter

class WithCustomTk(customtkinter.CTk):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.grid_columnconfigure(0, weight=1)

        self.font = customtkinter.CTkFont("Arial", 18)

        self.treeview_heading_style = ttk.Style(self)
        self.treeview_heading_style.theme_use("clam")
        self.treeview_heading_style.configure("Treeview.Heading", background="black", foreground="white",
                                              highlightthickness=0, bd=0, font=self.font)

        self.treeview_style = ttk.Style(self)
        self.treeview_style.theme_use("clam")
        self.treeview_style.configure("Treeview", background="black", foreground="white",
                                      highlightthickness=0, bd=0, font=self.font)

        self.treeview = ttk.Treeview(self, height=4, show="headings", selectmode="browse")
        self.treeview.grid(row=0, column=0, sticky="nsew")

        self.treeview["columns"] = ("one", "two", "three")

        self.treeview.heading("one", text="Column A")
        self.treeview.heading("two", text="Column B")
        self.treeview.heading("three", text="Column C")

        self.treeview.column("one", width=100)
        self.treeview.column("two", width=100)
        self.treeview.column("three", width=100)

        self.treeview.insert("", "end", values=("1", "2", "3"))
        self.treeview.insert("", "end", values=("4", "5", "6"))
        self.treeview.insert("", "end", values=("7", "8", "9"))

if __name__ == "__main__":
    app = WithCustomTk()
    app.mainloop()
Bildschirm­foto 2023-06-15 um 13 54 10
TomSchimansky commented 1 year ago

Duplicate of https://github.com/TomSchimansky/CustomTkinter/issues/1187