python - Making a grid of Entry boxes in Tkinter in a loop -


i want make grid of entry boxes can edit , save text file somewhere else, every time run code, if call variable "e", can edit last box made.

from tkinter import *  class application(frame):      def __init__(self, master):         frame.__init__(self, master)         self.grid()         self.create_widgets()      def create_widgets(self):         self.txtlist = open('txtlist.txt', 'r+')         self.row = self.txtlist.readline()         self.row = self.row.rstrip('\n')         self.row = self.row.replace('characters = ', "") #should end being "6"         self.columns = self.txtlist.readline()         self.columns = self.columns.rstrip('\n')         self.columns = self.columns.replace('columns = ', "") #should end being "9"         = 0         x = 0         in range (int(self.row)):             x in range (int(self.columns)):                 sroot = str('row' + str(i) + 'column' + str(x))                 e = entry(self, width=15)                 e.grid(row = i, column = x, padx = 5, pady = 5, sticky = w)                 e.delete(0, end)                 e.insert(0, (sroot))                 x = x + 1             x = 0             = + 1 root = tk() root.title("longevity") root.geometry("450x250") app = application(root) root.mainloop() 

i store entries in sort of data structure have easy access them later. list of lists work nicely this:

    self.entries = []     in range (int(self.row)):         self.entries.append([])         x in range (int(self.columns)):             ...             e = entry(self, width=15)             self.entries[-1].append(e)             ... 

now have reference entry box:

 self.entries[row_idx][col_idx] 

and can modify want.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -