Python Forum
Spacing Between two labels are very far and Top label is not in Center using Tkinter - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Spacing Between two labels are very far and Top label is not in Center using Tkinter (/thread-20158.html)



Spacing Between two labels are very far and Top label is not in Center using Tkinter - barry76 - Jul-30-2019

Hey, I have been working with Tkinter code using grid and with some certain ways of using pack at same time, as mentioned below in code.

    def __init__(self, master):
        super().__init__(master, bg='powder blue')
        Frame1 = tk.Frame(self.master, bg='powder blue')
        Frame1.pack(side="bottom", fill="x", pady=10, anchor='n')
        Frame2 = tk.Frame(self.master, bg='powder blue')
        Frame2.pack(side="left", fill="both", pady=10, anchor='n')
        self.master.geometry('1350x750+0+0')
        self.master.config(bg='powder blue')
        tk.Label(Frame2, text='Reference System', font=('arial', 30, 'bold'), bg='powder blue',
                 fg='black').grid(pady=10)
        tk.Label(Frame2, text="Accuracy: ", bg='powder blue', font=('arial', 12, 'bold')).grid(row=3)
        self.text = tk.StringVar()
        tk.Label(Frame2, textvariable=self.text, bg='powder blue',font=('arial', 12, 'bold')).grid(row=3, column=1)
        tk.Label(Frame2, text="No of Jobs: ", bg='powder blue', font=('arial', 12, 'bold')).grid(row=3,column=2)
        self.text1 = tk.StringVar()
        tk.Label(Frame2, textvariable=self.text1, bg='powder blue',font=('arial', 15, 'bold')).grid(row=3, column=3)
        b = tk.Button(Frame2, text="Display", command=self.loopCap)
        b.grid(row=6, column=2, pady=5)
        self.label = tk.Label(Frame1,bg='powder blue')
        self.label.grid(row=7, column=1, pady=5)
        self.label1 = tk.Label(Frame1, bg='powder blue')
        self.label1.grid(row=7, column=2, pady=5)
        print("Load")
but I am not able to understand why I am getting so much space while initializing "row=3 and column 0" between "Accuracy" label and "text variable = self.text"

Please check the Snap Attachment fo further info


Suggestions on this will be very helpful


RE: Spacing Between two labels are very far and Top label is not in Center using Tkinter - Larz60+ - Jul-30-2019

Be consistent ant when using grid for your labels.
in some you assign row and column
in another just row
and in another neither.


RE: Spacing Between two labels are very far and Top label is not in Center using Tkinter - wuf - Jul-30-2019

Hi barry76

Please note the adviced instructions of Larz60+. Try to present executable code snippets. If possible do not mix pack with grid.

For further studies i have placed here following script:
import tkinter as tk

APP_XPOS = 0
APP_YPOS = 0
APP_WIDTH = 1350
APP_HEIGHT = 750
APP_BG_COLOR = 'powder blue'

TEXT_BG = 'white' # powder blue',

class MyClass(tk.Frame):
    
    def __init__(self, master):
        super().__init__(master, bg=APP_BG_COLOR)
        
        tk.Label(self, text='Reference System', bg='powder blue', fg='black',
            font=('arial', 30, 'bold')
            ).pack(pady=10)

        entry_frame = tk.Frame(self, bg=APP_BG_COLOR)
        entry_frame.pack(padx=10, pady=10)

        tk.Label(entry_frame, text="Accuracy: ", bg='powder blue',
            font=('arial', 12, 'bold')
            ).pack(side='left', padx=4)

        self.text = tk.StringVar(master, "Text")
        tk.Label(entry_frame, textvariable=self.text, bg=TEXT_BG, 
            font=('arial', 12, 'bold'), width=30
            ).pack(side='left')

        tk.Label(entry_frame, text="No of Jobs: ", bg='powder blue',
            font=('arial', 12, 'bold')
            ).pack(side='left', padx=4)

        self.text1 = tk.StringVar(master, "Text1")
        tk.Label(entry_frame, textvariable=self.text1, bg=TEXT_BG, 
            font=('arial', 12, 'bold'), width=30
            ).pack(side='left')

        tk.Button(self, text="Display", command=self.loopCap
            ).pack()
                
        image_frame = tk.Frame(self, bg='powder blue')
        image_frame.pack(fill="both", expand=True, padx=10, pady=10)
        
        self.label = tk.Label(image_frame, bg='green') #powder blue')
        self.label.pack(side='left', fill='both', expand=True, padx=5, pady=5)
        
        self.label1 = tk.Label(image_frame, bg='yellow') #'powder blue')
        self.label1.pack(side='left', fill='both', expand=True, padx=5, pady=5)
        print("Load")

    def loopCap(self):
        print("Loop Cap")

root = tk.Tk()
root.geometry('{}x{}+{}+{}'.format(APP_WIDTH, APP_HEIGHT, APP_XPOS, APP_YPOS))
root.config(bg=APP_BG_COLOR)
        
MyClass(root).pack(fill='both', expand=True)

root.mainloop()
wuf :-)