I'm going to ask the user to enter a number in an entry and press the 'enter' button, then show that number of entries below on the window, here is my code, the test class makes a list of entries and it works well alone but when I combine it with the first scenario and press the button nothing happens:
from tkinter import *
root = Tk()
root.geometry("600x600+50+50")
font = ('Verdana', 10)
def enter():
try:
class test:
def __init__(self, root):
self.variables = []
n = eval(txt_num.get())
for i in range(n):
self.variables.append(StringVar())
self.labels = []
self.entrys = []
mod = n % 4
c = 0
d = 0
e = 0
for ii in range(int(n/4)):
for jj in range(4):
char = c+(jj+1)
self.labels.append(Label(root , text = char))
self.labels[-1].grid(padx=0, pady=0, row=ii+d+1, column=jj)
self.entrys.append(Entry(root, textvariable =self.variables[c+(jj+1)]))
self.entrys[-1].grid(padx=0, pady=0, row=ii+d+2, column=jj)
d+=2
c+=4
e = ii+d+1
for kk in range(mod):
char = c+(kk+1)
self.labels.append(Label(root , text = char))
self.labels[-1].grid(padx=0, pady=0, row=int(n/4)+1+e+1, column=kk)
self.entrys.append(Entry(root, textvariable =self.variables[c+(kk)]))
self.entrys[-1].grid(padx=0, pady=0, row=int(n/4)+1+e+2, column=kk)
T = test(root)
except:
pass
lable_num = Label(font = font, text = 'Enter the number of your numbers:')
lable_num.grid(row = 0 , column = 0, columnspan = 3)
txt_num = Entry(width = 15, font = font, fg = 'gray' )
txt_num.grid(row = 0 , column = 4)
button_enter = Button(text = 'Enter' , font = font, command = enter())
button_enter.grid(row = 0 , column = 5)
root.mainloop()