mardi 13 décembre 2016

Tkinter: Checkbuttons and list

Hey Guys I have a problem with checkboxen in tkinter. Can someone say where my fault is ?

def edit_contact_gui(self):
    """GUI to edit the created contacts."""
    self.edit_contact_wd = tk.Tk()
    self.edit_contact_wd.title('Edit Contacts of the Phonebook:"%s"'\
                               % self.book)
    self.button_edit = tk.Button(self.edit_contact_wd, text = 'Edit',\
                                 command = self.edit_contact)


    try:
        with open('%s.txt' % self.book, 'rb') as file:
            book = pickle.load(file)
            x = 1
            self.var_lst = []
            for i in book:
                var = tk.IntVar()
                tk.Label(self.edit_contact_wd, text = i).grid(row = x, \
                                                                column = 0)

                tk.Checkbutton(self.edit_contact_wd, text = 'edit', \
                               variable = var).grid(row = x, column = 1)
                self.var_lst.append(var.get())

                x += 1

            self.button_edit.grid(row = x+1, column = 1)

    except FileNotFoundError:
        tk.Label(self.edit_contact_wd, text = 'The phonebook has no entrys!', fg = 'red').grid(row = 1, column = 0)

    self.edit_contact_wd.mainloop()

def edit_contact(self):
    print(self.var_lst)

My GUI output works, but the programm return me a List [0,0,0,0,0] full of zeros. In my opinion the Checkbox who is marked has return a 1 but it doesnt to it. Why? Can you help me ?




Aucun commentaire:

Enregistrer un commentaire