tkinter checkboxes
Verfasst: Dienstag 13. Dezember 2016, 12:37
Hey Leute ich verstehe nicht ganz warum meine Checkboxen nicht funktionieren kann mir jemand sagen wo mein Fehler liegt ?
Meine Ausgabe, als GUI funktioniert. Jedoch muss mir das Programm meiner Meinung nach in der Shell später durch die Funktion eine Liste mit 0 und 1 ausgeben. 0 dafür wo kein Hacken ist und 1 wo ich ein Hacken habe. Dies macht es jedoch nicht es gibt mir immer Listen aus mit 0 . Warum macht der Code das, wo liegt mein Fehler.
PS: habe natürlich
import pickle und import tkinter as tk, am Anfang meines Programmes.
Danke schonmal im vorraus.
Code: Alles auswählen
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)
def edit_contact(self):
print(self.var_lst)
self.edit_contact_wd.mainloop()PS: habe natürlich
import pickle und import tkinter as tk, am Anfang meines Programmes.
Danke schonmal im vorraus.