Python Forum
Spacing Between two labels are very far and Top label is not in Center using Tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spacing Between two labels are very far and Top label is not in Center using Tkinter
#1
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

Attached Files

Thumbnail(s)
   
Reply
#2
Be consistent ant when using grid for your labels.
in some you assign row and column
in another just row
and in another neither.
Reply
#3
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 :-)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGTK] How to center text on multi-line buttons? Lomax 2 67 3 hours ago
Last Post: Axel_Erfurt
  tkinter: Image to Label Maryan 10 480 Oct-29-2020, 01:48 PM
Last Post: joe_momma
  Updating labels Wenkar7000 2 233 Oct-20-2020, 10:49 AM
Last Post: DeaD_EyE
  Tkinter - How can I extend a label widget? TurboC 2 307 Oct-13-2020, 12:15 PM
Last Post: zazas321
  Tkinter: How to assign calculated value to a Label LoneStar 7 478 Sep-03-2020, 08:19 PM
Last Post: LoneStar
  Tkinter having problems with packing labels? wallgraffiti 0 265 Aug-02-2020, 09:26 AM
Last Post: wallgraffiti
  changing tkinter label from thread nanok66 3 864 Jun-07-2020, 01:37 AM
Last Post: nanok66
  Creating and destroying dynamic labels in Tkinter MarcusRoberts 1 712 May-02-2020, 06:49 PM
Last Post: Yoriz
  [Tkinter] tkinter How to pass label fiilename to another module? johnjh 0 558 Apr-17-2020, 11:34 PM
Last Post: johnjh
  Make Label Text background (default color) transparent using tkinter in python barry76 1 9,844 Nov-28-2019, 10:19 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020