python - "Resetting" the arguments of a variable -
i trying reset arguments in variable def sequence when user inputs invalid sequence. otherwise runtimeerror: maximum recursion depth exceeded error because argument stored in def sequence remains invalid. suggestions? thinking of putting "self.sequence(none)" in else: adds argument def sequence seems.
from tkinter import * class at_content_calculator: def __init__(self, master): #initialising various widgets frame_1 = frame(master) frame_1.pack() self.varoutput_1 = stringvar() self.label_1 = label(frame_1, text="please enter dna sequence:") self.label_1.pack() self.entry_1 = entry(frame_1, textvariable=self.sequence) self.entry_1.pack() self.output_1 = label(frame_1, textvariable=self.varoutput_1) self.output_1.pack() self.button_1 = button(frame_1, text="calculate", command=self.validation_check) self.button_1.pack() def sequence(self): self.dna_sequence = self.entry_1.get() return self.dna_sequence def validation_check(self): #used validate self.dna_sequence contains letters g, c, a, t valid = 'gcat' condition = all(i in valid in self.sequence()) if condition: self.at_calculate() else: self.varoutput_1.set("invalid dna sequence. please enter again.") self.validation_check() def at_calculate(self): #used calculate @ content of string stored in self.dna_sequence self.dna_sequence = self.entry_1.get() self.total_bases = len(self.dna_sequence) self.a_bases = self.dna_sequence.count("a") self.b_bases = self.dna_sequence.count("t") self.at_content = "%.2f" % ((self.a_bases + self.b_bases) / self.total_bases) self.varoutput_1.set("at content percentage: " + self.at_content) root = tk() root.title("at content calculator") root.geometry("320x320") b = at_content_calculator(root) root.mainloop()
the problem isn't "resetting" value of variable. problem repeatedly call validation_check
within without changing value being validated, naturally end recursion error. shouldn't call method again @ all: show message telling user validation has failed, nothing , wait them change value , press button again.
(and looping better here recursion, anyway; don't need either, let method end.)
Comments
Post a Comment