0

I have a tkinter app which displays certain information in the GUI and there are 5 columns to display this information in. To place these elements, I'm using the .grid() command. The problem is it doesn't actually span the whole width of the frame. This is what it's giving me right now (highlighted red to show where the columns are):

The intended column names are "Component" "Directory" "File name" "Lines Covered" and "Conditionals Covered". I would like this to span the whole width of the white frame with equal spacing for each column (5 of them). How can I fix this??

Some code I have to fill in the data:

def populate_metric_frame(self, frame, files_changed, utests_changed):

    tk.Label(frame, text="Component",  font=("Courier", 8), bg=Window.det_uncov_color).grid(
        sticky="NESW", row=0, column=0)

    tk.Label(frame, text="Directory",  font=("Courier", 8), bg=Window.det_uncov_color).grid(
        sticky="NESW", row=0, column=1)

    tk.Label(frame, text="File name",  font=("Courier", 8), bg=Window.det_uncov_color).grid(
        sticky="NESW", row=0, column=2)

    tk.Label(frame, text="Lines Covered",  font=("Courier", 8), bg=Window.det_uncov_color).grid(
        sticky="NESW", row=0, column=3)

    tk.Label(frame, text="Conditionals Covered",  font=("Courier", 8), bg=Window.det_uncov_color).grid(
        sticky="NESW", row=0, column=4)

    tk.Label(frame, text="----------------------",  font=("Courier", 8), bg=Window.det_uncov_color).grid(
        sticky="NESW", row=1, column=0, columnspan=5)


    #Many more items down here

Some code I have to make the frame:

    # Create and place the title for the "Developer Feedback" frame
    self.feedback_title = tk.Label(
        self.feedback_frame, text="Metrics", bg=Window.frame_color1, font=("Courier", 11))
    self.feedback_title.place(relwidth=1, anchor="nw")

    # Create and place the frame to hold the canvas for "Developer Feedback"
    self.metric_list_frame = tk.Frame(
        self.feedback_frame, bg=Window.frame_color1)
    for i in range(5):
        self.metric_list_frame.grid_columnconfigure(i, weight=1)
    self.metric_list_frame.place(rely=0.1, relwidth=1, relheight=0.9)

    # Create and place the canvas
    self.metric_list_canvas = tk.Canvas(
        self.metric_list_frame, bg=Window.det_text_color, bd=0)
    for i in range(5):
        self.metric_list_canvas.grid_columnconfigure(i, weight=1)
    self.metric_list_canvas.place(relwidth=1, relheight=1)

    # Create and place the frame to hold the text
    self.metric_list_canvas_frame = tk.Frame(
        self.metric_list_canvas, bg=Window.det_text_color)
    for i in range(5):
        self.metric_list_canvas_frame.grid_columnconfigure(i, weight=1)
    self.metric_list_canvas_frame.bind("<Configure>", lambda event,
                                       canvas=self.metric_list_canvas: self.onFrameConfigure(self.metric_list_canvas))

    # Create and place the scrollbar
    self.metric_list_scrollbar = tk.Scrollbar(
        self.metric_list_canvas, orient="vertical", command=self.metric_list_canvas.yview)
    self.metric_list_scrollbar.pack(side="right", fill="y")

    # Define how the scrollbar works
    self.metric_list_canvas.configure(
        yscrollcommand=self.metric_list_scrollbar.set)
    self.metric_list_canvas.create_window(
        (1, 1), window=self.metric_list_canvas_frame, anchor="nw")

    # Fill the table with a list of changed files
    self.populate_metric_frame(
        self.metric_list_canvas_frame, files_changed, utests_changed)

P.S. I'm sorry about the trainwreck of code formatting but I'm still starting so I'm still learning the best way to format. Thank you for any help

Edit: The suggested link only explains how to stretch the "------", which is also what I want. But I need the column headers as well

  • 1
    Does this answer your question? [How to stretch cell horizontally using grid in Tkinter?](https://stackoverflow.com/questions/63014842/how-to-stretch-cell-horizontally-using-grid-in-tkinter) – Thingamabobs Aug 04 '20 at 16:45
  • 1
    Take a look on this too https://stackoverflow.com/questions/63189654/trouble-using-tkinter-grid/63191526#63191526 – Thingamabobs Aug 04 '20 at 16:52
  • @Atlas435 I'll take a look, thanks! –  Aug 04 '20 at 16:53

0 Answers0