1

I want between button and label to be at minimum 6 rows of grid framework based. I put ttk.Label(mainframe, text="enter url ").grid(column=3, row=1, sticky=('N')) row is one, and sticky which is North.

If the cell is larger than the widget, the sticky option specifies which side the widget should sticks to and how to distribute any extra space within the cell that is not taken up by the widget at its original size.

And with button button.grid(column=3, row=7, sticky=tk.S) stiky to South, if there is space, and row start from 7. When you run you see that they are near each other like row =3 in button.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.title("Your App crawler")

mainframe = ttk.Frame(root)

mainframe.grid(column=0, row=0, sticky=('N'))
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

feet = tk.StringVar()
feet_entry = ttk.Entry(mainframe, width=21, textvariable=feet)
feet_entry.grid(column=0, row=1, sticky=(tk.N),ipadx=100)
feet_entry.focus()

ttk.Label(mainframe, text="enter  url ").grid(column=3, row=1, sticky=('N')) #attention:row is 1

def crawler():

button = ttk.Button(mainframe, text="scrape", command=crawler)
button.grid(column=3, row=7, sticky=tk.S) #even though row is 7, and sticky equals 'S'
root.bind("<Return>", crawler)

for child in mainframe.winfo_children():
    child.grid_configure(padx=5, pady=5)
root.mainloop()

Why it is so, and how to change the way I desire? Nice resource for practice enter link description here

Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
xlmaster
  • 659
  • 7
  • 23
  • 1
    What do you mean `minimum 6 rows`? How big is a row? You have to have something in between rows for them to have spacing. You could try using weights and assign a weight to the empty rows to give them space – TRCK Oct 19 '22 at 13:02
  • you mean by adjusting `root.rowconfigure(0, weight=1)` this weight values I guess. I tried by 3 no effect – xlmaster Oct 19 '22 at 13:04
  • 4
    rows without widgets will have zero height. However you can use `.rowconfigure((3,4,5,6,7), uniform=1)` to override it. – acw1668 Oct 19 '22 at 13:08
  • can I put two label with background color same with main frame with width =3 each? – xlmaster Oct 19 '22 at 13:09

1 Answers1

1

Answer from User @acw1668 helped to work out it;

ttk.Label(mainframe).grid(column=3, row=3, sticky=('N')) ttk.Label(mainframe).grid(column=3, row=3, sticky=('N'))#?

By putting two labels with row 3 and without text I managed to get 6 row space. Thanks for help

xlmaster
  • 659
  • 7
  • 23