pythontkintertkinter-layout

Tkinter treeview not being placed at the right coordinates


I have placed a treeview widget in my tk window with .place() but it is being placed in the wrong coordinates, around 100 pixels off in both x and y, verging closer to 0. The size of the treeview is also affected, making it smaller than it should be. None of my other widgets have this problem.

This only happens on my laptop and not on any other computers. My laptop display is 1920x1080.

Are there any settings that would fix this?

Here is an example. The buttons are placed at the same coordinates as the treeview, but for me, the buttons appear at the right coordinates but the treeviews don't.

import tkinter as tk
from tkinter import ttk
import customtkinter as ctk

class Example(ctk.CTk):
    def __init__(self, *args, **kwargs):
        super().__init__()

        self.geometry('720x800')
        self.resizable(False, False)

        container = ctk.CTkFrame(master=self)
        container.pack(side='top', fill='both', expand=True)
        
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames={}

        for F in (A, B):
            frame = F(container, self)
            self.frames[F] = frame
            frame.grid(row=0, column=0, sticky= 'nsew')
            frame.grid_columnconfigure(0,weight=1)
            frame.grid_rowconfigure(0,weight=1)
             

        self.show_frame(A) 

    def show_frame(self, cont):
        frame = self.frames[cont] 
        frame.tkraise()

class A(tk.Frame): 
    def __init__(self,parent, controller):
        tk.Frame.__init__(self, parent, bg='grey') 

        columns = ('ID', 'First Name', 'Last Name', 'Email')
        self.tree = ttk.Treeview(self, columns=columns, show='headings', height=10, selectmode='browse')
        self.tree.place(x=100, y=400)

        #Add Headings 
        for i in range(len(columns)): 
                self.tree.heading(columns[i], text=columns[i])

        #Configure column sizes 
        for i in range (len(columns)): 
                self.tree.column(columns[i], width=141)

        recs = [[1,2,3,4], [1,2,3,4]]
        for row in recs:
            self.tree.insert('', tk.END, values=row)

        self.button = ctk.CTkButton(master=self, 
                                    text='Next page', 
                                    command=lambda:controller.show_frame(B))
        self.button.place(x=100, y=400)

class B(tk.Frame): 
     def __init__(self,parent, controller):
        tk.Frame.__init__(self, parent, bg='grey')

        columns = ('ID', 'First Name', 'Last Name', 'Email')
        self.tree = ttk.Treeview(self, columns=columns, show='headings', height=10, selectmode='browse')
        self.tree.place(x=100, y=400)

        #Add Headings 
        for i in range(len(columns)): 
                self.tree.heading(columns[i], text=columns[i])

        #Configure column sizes 
        for i in range (len(columns)): 
                self.tree.column(columns[i], width=141)

        recs = [[6,7,8,9], [1,2,3,4]]
        for row in recs:
            self.tree.insert('', tk.END, values=row)

        self.button = ctk.CTkButton(master=self, 
                                    text='Prev page', 
                                    command=lambda:controller.show_frame(A))
        self.button.place(x=100,y=400)
        

if __name__ == '__main__': 
    testWindow= Example() 
    testWindow.mainloop()

On my laptop: enter image description here

What it's supposed to look like: enter image description here


Solution

  • Solution:

    Make sure that your scaling (System>Display>Scale) is set at 100%.