def enable_buttons(self): # get a list of all existing problem ids problem_ids = db.get_problem_ids(conn) # configure clicking function for all the delete buttons for qid in problem_ids: self.deletes[qid].config(command=lambda j=qid: self.del_problem(j)) # configure clicking function for all the update buttons for qid in problem_ids: self.updates[qid].config(command=lambda j=qid: self.up_problem(j))
def init_problems_in_lb(self): '''initialises the problems and puts them in the list box''' lb = self.list_box["problems"] # create a label_string label_string = "qid subject question answer" lb.insert(END, label_string) # get all the problem ids ids = db.get_problem_ids(conn) for qid in ids: problem_string = self.string_qid(qid) lb.insert(END, problem_string)
def init_problems_in_lb(self): '''initialises the problems and puts them in the list box''' lb = self.list_box["problems"] # create a label_string label_string = "{:<3} {:<7} {:<10} {:<15} {:<10}" label_string = label_string.format("qid", "subject", "question", "answer", "hint") lb.insert(END, label_string) # get all the problem ids ids = db.get_problem_ids(conn) for qid in ids: problem_string = self.string_qid(qid) lb.insert(END, problem_string)
def gen_rows(self): # get a list of all the problem ids in the database ids = db.get_problem_ids(conn) # set iterator for grid rows i = 0 # for each id create a row for qid in ids: # create new entries subject_entry = ttk.Entry(self, font=REGULAR_FONT) question_entry = ttk.Entry(self, font=REGULAR_FONT) answer_entry = ttk.Entry(self, font=REGULAR_FONT) # add to corresponding dictonaries with problem ids as keys self.subjects[qid] = subject_entry self.questions[qid] = question_entry self.answers[qid] = answer_entry # create new buttons update_button = ttk.Button(self, text="Update") delete_button = ttk.Button(self, text="Delete") # add to corresponding dictonaries with problem ids as keys self.deletes[qid] = delete_button self.updates[qid] = update_button # set everything nicely on the grid using an iterator i subject_entry.grid(row=i+3, column=0) question_entry.grid(row=i+3, column=1) answer_entry.grid(row=i+3, column=2) update_button.grid(row=i+3, column=3) delete_button.grid(row=i+3, column=4) i += 1 # create new problem object to contain problem info problem = Problem(qid) # set each entry with the corresponding value from the problem object subject_entry.insert(0, problem.get_subject()) question_entry.insert(0, problem.get_question()) answer_entry.insert(0, problem.get_answer())
>>>>>>> working_final def init_problems_in_lb(self): '''initialises the problems and puts them in the list box''' lb = self.list_box["problems"] # create a label_string <<<<<<< HEAD label_string = "qid subject question answer hint" ======= label_string = "{:<3} {:<7} {:<10} {:<15} {:<10}" label_string = label_string.format("qid" ,"subject", "question", "answer", "hint") >>>>>>> working_final lb.insert(END, label_string) # get all the problem ids ids = db.get_problem_ids(conn) for qid in ids: problem_string = self.string_qid(qid) lb.insert(END, problem_string) def string_qid(self, qid): '''creates a string to add to list box based on the uid''' problem_string = "{:<3} {:<7} {:<10} {:<15} {:<10}" # get the problem from the id problem = Problem(qid) # create a string to hold the result of the problem problem_string = problem_string.format(qid, problem.get_subject(), problem.get_question(), problem.get_answer(), problem.get_hint()) # place the string inside the list_box return problem_string