mardi 13 novembre 2018

Tkinter checkbox split list

I'm trying to split a list from a file with ~ 100 items to several lines of checkboxes (10 per line ~). Because all items are on the same long line.

I tried to split the first file into nFiles with 10 items max and create new lines of checkbutton in the frame. But no way, i got only all items in the same line:

class DisplayApp(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title("My Menu")
        frame_1 = tk.LabelFrame(self, text="Frame 1")
        frame_1.grid(row=2, columnspan=3, sticky='WE', padx=5, pady=5, ipadx=5, ipady=5)
        path = '/home/lst/*.txt'
        files=glob.glob(path)
        for file in files:
            with open(file, 'r') as lst_file:
                for item in lst_file:
                    tk.Checkbutton(frame_1, text=item.rstrip()).pack(side=tk.LEFT)

if __name__ == "__main__":
    DisplayApp().mainloop()

Initiale txt file:

item1 
item2
item3
...
item100

Many thanks for your help




Aucun commentaire:

Enregistrer un commentaire