Python Forum

Full Version: Spacing Between two labels are very far and Top label is not in Center using Tkinter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.config(bg='powder blue')
        tk.Label(Frame2, text='Reference System', font=('arial', 30, 'bold'), bg='powder blue',
        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)
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
Be consistent ant when using grid for your labels.
in some you assign row and column
in another just row
and in another neither.
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_WIDTH = 1350
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')

        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

        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

        tk.Button(self, text="Display", command=self.loopCap
        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)

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

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

wuf :-)