0

I'm trying to make a GUI for my program, and it looks kinda like this

the entry at the top doesn't work yet and that's what I'm working on right now. I want to make that if I insert any number to the top entry box and click OK, it will automatically added rows of entry corresponds to that number

Right now what I'm doing is to link each number (I only make from 1-5) to function where 1 corresponds to 1 row of entry, and if I type 2, there will be 2 rows of entries, and so on

But I know doing it that way is wrong,Is there any way that if I insert any number into the top entry box, there will be new row of entry box that is automatically added?

This is probably what i wanted it to be like tkinter2

KaraiKare
  • 155
  • 1
  • 2
  • 10
  • Do you want to be able to create any number of new Entry widgets, or will there be a known maximum (like 5). If there's a maximum, either disable the unwanted Entry widgets, or hide them using `.pack_forget` or `.grid_forget`, as Bryan says [here](http://stackoverflow.com/a/10268076/4014959). – PM 2Ring Dec 02 '16 at 08:55
  • I want to create any number if possible actually, so whatever number ('n') I put into the top entry box, then there will be 'n' number of the entries row – KaraiKare Dec 02 '16 at 09:22
  • 1
    In that case, I suggest you use the scrollable Frame code from [this answer](http://stackoverflow.com/a/16198198/4014959) to display your Entry widgets, so you won't be limited by the screen height. You can create the widgets using a `for` loop and store them in a list. If you need further help you will need to post some code, preferably a [mcve]. – PM 2Ring Dec 02 '16 at 09:39
  • Thank you very much, will try looking into that – KaraiKare Dec 02 '16 at 10:40

1 Answers1

0

Suppose the four entry boxes are E1, E2, E3, E4. And the button for OK is B. The addition is to be performed by the function Add. Following is how you do it(I've put only one entry, you can put as many as you want and repeat the same process) :

import tkinter as tk
from tkinter import *
root=tk.Tk()

X0=IntVar()
X1=IntVar()

E0=Entry(root, textvariable=X0)
E0.grid()
E1=Entry(root, textvariable=X1)
E1.grid()

def Add():
    x=X0.get()
    y=X1.get()
    E1.delete(0,END)
    E1.insert(END,x+y)

B=Button(root, command=lambda: Add())
B.grid()

root.mainloop()

Hope this helps..

Eshita Shukla
  • 791
  • 1
  • 8
  • 30