Oct-19-2021, 07:45 AM
I have defined an entry via the following class:
class Entry(object): def __init__(self):#, foo1, foo2, nac, root, row): #*args, **kwargs): self.foo1 = tk.StringVar(value='default text') self.foo2 = tk.StringVar(value='default text') self.nac = tk.IntVar() self.root = None self.row = None self.ck1 = tk.Checkbutton(self.root, variable=self.nac, command=self.naccheck) self.ck1.grid(row=self.row, column=0, sticky='ne') self.ent1 = tk.Entry(self.root, width=20, background='white', textvariable=self.foo1, state='normal') self.ent1.grid(row=self.row, column=1, sticky='ns') self.ent2 = tk.Entry(self.root, width=20, background='white', textvariable=self.foo2, state='disabled') self.ent2.grid(row=self.row, column=2, sticky='nw') print(self.row) def naccheck(self): if self.nac.get() == 0: self.ent2.configure(state='disabled') else: self.ent2.configure(state='normal') def get_on_click(self): print(self.ent1.get(), self.ent2.get())now I want to define the entry voer a loop:
import scripts.modules as md import tkinter as tk if __name__ == '__main__': main_root = tk.Tk() width = 300 height = 40 main_root.geometry('{}x{}'.format(width, 10 * height)) main_root.configure(background='cyan') top_frame = tk.Frame(main_root, bg='green', padx=10, pady=5, width=width, height=100) top_frame.grid(row=0, columnspan=width, sticky='ns') input_frame_left = tk.Frame(main_root, bg='red', padx=10, pady=5, width=width, height=100) input_frame_left.grid(row=1, columnspan=width, sticky='ns') # # print(type(main_root)) for i in range(10): gui_entry = md.Entry() gui_entry.root = top_frame # gui_entry. = 'aaaaaaaaaa' gui_entry.row = i button = tk.Button(input_frame_left, text="click me", command=gui_entry.get_on_click) button.grid(row=10, columnspan=3) main_root.mainloop()why do the entry appear on different lines? what am I doinig wrong?[attachment=1337]