I'm trying to learn python and tkinter since few days. I would like to create dynamic checkboxes (values from a file) in a frame.
This is my code:
import tkinter as tk
lst="lst.txt"
class DisplayApp:
def __init__(self):
self.root = tk.Tk()
self.root.title("My Menu")
self.build_gui()
def build_gui(self):
frame_1 = tk.LabelFrame(self.root, text="Frame 1")
frame_1.grid(row=2, columnspan=3, sticky='WE',
padx=5, pady=5, ipadx=5, ipady=5)
linestring = open(lst, 'r').read()
for checkBoxName in linestring:
c = tk.Checkbutton(frame_1, text=checkBoxName,)
c.pack(side=tk.LEFT)
def clicked(self):
pass
def main(self):
self.root.mainloop()
if __name__ == "__main__":
app = DisplayApp()
app.main()
This is the file lst.txt:
laptopname_1
laptopname_2
laptopname_3
laptopname_n
...
This the error:
[root@hdid_master ~]# ./test_menu_2.py
File "./test_menu_2.py", line 35
for checkBoxName in linestring:
^
TabError: inconsistent use of tabs and spaces in indentation
Many thanks for your help. Best Regards.
Aucun commentaire:
Enregistrer un commentaire