0

I have attached two images showing the layout that I am currently getting (Image 1) and the layout which I want (Image 2), (Label 3 at position of GREEN BOX and Entry 1 at position of PURPLE BOX). Can i get output as image 2 using pack() or do I need to either grid() or place()?

I am getting this layout:

enter image description here

I want this type of layout:

enter image description here

My code for Image 1 [I am currently getting]

from tkinter import *

root = Tk()
root.geometry('1000x700+0+0')
root.minsize('1000','700')

f1 = Frame(root, bd=5, relief=GROOVE, width=500, height=500)
f1.pack(fill=BOTH, expand=True, padx=30, pady=30)

f2 = Frame(f1, bg='pink', bd=5, relief=GROOVE)
f2.place(anchor=CENTER, relx=0.5, rely=0.5, relwidth=0.8, relheight=0.8)

lbl_1 = Label(f1, text='Label 1',  bg='yellow', bd=2.5, relief=GROOVE,  font=('Times New Roman',20,'bold'))
lbl_1.pack(side=TOP, pady=5)

lbl_2 = Label(f2, text='Label 2',  bg='yellow', bd=2.5, relief=GROOVE,  font=('Times New Roman',20,'bold'))
lbl_2.pack(side=TOP, pady=5)

lbl_3 = Label(f2, text='Label 3', bg='yellow', bd=2.5, relief=GROOVE,  font=('Times New Roman',15,'bold'))
lbl_3.pack(pady=10)

txt_1 = Entry(f2, text='Txt 1', bd=2.5, relief=SUNKEN,  font=('Times New Roman',15,'bold'))
txt_1.pack(pady=10)

lbl_4 = Label(f2, text='Label 4',  bg='yellow', bd=2.5, relief=GROOVE,  font=('Times New Roman',20,'bold'))
lbl_4.pack(side=BOTTOM, pady=5)

root.mainloop()
DaveL17
  • 1,673
  • 7
  • 24
  • 38
Prem
  • 23
  • 4

1 Answers1

0

Need to use anchor="w" in .pack(...) to move the label and entry to the left side and add horizontal margin using padx:

...
lbl_3.pack(padx=30, pady=10, anchor="w")
...
txt_1.pack(padx=30, pady=10, anchor="w")
...
acw1668
  • 40,144
  • 5
  • 22
  • 34