Bottom Page

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)
   
Quote
#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.
Quote
#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 :-)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Unable to update or refresh label text in tkinter jenkins43 3 273 Jul-24-2019, 02:09 PM
Last Post: Friend
  [Kivy] Weird spacing in grid layout test 0 248 Jun-22-2019, 08:30 PM
Last Post: test
  tkinter label error nonzzo 1 489 Mar-31-2019, 01:29 PM
Last Post: Larz60+
  [Tkinter] How do I center this text in tkinter? ejected 4 2,741 Mar-29-2019, 10:35 PM
Last Post: woooee
  [Tkinter] TkInter toggle Label on/off MTom5 2 1,543 Aug-15-2018, 12:35 AM
Last Post: metulburr
  [Tkinter] tkiner spacing on a canvas help Chuy 1 765 Jul-21-2018, 08:02 PM
Last Post: Chuy
  [Tkinter] Displaying file's contents as labels gellerb 3 867 Apr-02-2018, 01:35 AM
Last Post: Larz60+
  printing option menu variable in label in Tkinter SmokerX 1 2,321 Jan-18-2018, 07:36 PM
Last Post: SmokerX
  Tkinter/Label/Arduino/ if Else condition emrebt39 1 1,699 Oct-20-2017, 11:44 AM
Last Post: Larz60+
  Help with tkinter Button and Label interaction issues ... sealyons 0 2,277 Jun-01-2017, 06:58 PM
Last Post: sealyons

Forum Jump:


Users browsing this thread: 1 Guest(s)