Search code examples
pythonpython-3.xfor-looptkintertkinter-entry

Placement of multiple tkinter entries starting at a particular value


Given below is a sample code derived from my main project, I'm able to place several entries using a for loop but I want it to start the y placement from 150(currently it starts from 80). The formula I used to place my entries is given as dist below, i.e ((i*30)+50). The distance between each entry is alright, thus I don't wish to change that, I merely wish to change the starting value.

from tkinter import *

root=Tk()
entries = []
root.geometry("500x500")
ing = []

for i in range(10):
    dist = ((i*30) + 50)
    en = Entry(root)
    en.place(x = "50", y=f"{dist}")
    entries.append(en)

def ent():
    for entry in entries:
        ing.append(entry.get())
    print(ing)

button=Button(root,text="get",command=ent).place(x="200", y="400")

root.mainloop()

Given below is my output, I want my whole list of entries to be pushed down and started from a greater y value. image


Solution

  • The way to tackle this problem is by editing your formula for distance, and saying

    for i in range(10):
        dist = ((i*40) + 100)
        en = Entry(root)
        en.place(x=50, y=dist)
        entries.append(en)
    

    Hope this helped. Happy Coding

    Cheers