[Tkinter] Tkinter callback exception - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Tkinter callback exception (/thread-41603.html) |
Tkinter callback exception - Ben123 - Feb-15-2024 Exception in Tkinter callback Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tkinter/__init__.py", line 1948, in __call__ return self.func(*args) ^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/customtkinter/windows/widgets/ctk_button.py", line 554, in _clicked self._command() floatVar = float(self.Answer_Text_Variable.get()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: could not convert string to float: '' def Mark(self): floatVar = float(self.Answer_Text_Variable.get()) print(self.Answer_Text_Variable.get()) if floatVar == self.Correct_Answer: self.Question_Answer_entry.configure(fg_color = "#90EE90") self.Answer_message_Label.configure(text = 'Correct!') self.Answer_message_Label.place(relx = 0.6, rely = 0.66) self.Correct = 1 else: self.Question_Answer_entry.configure(fg_color = "#FF3131") self.Answer_message_Label.place(relx = 0.6, rely = 0.66) print(f'You put {self.Answer_Text_Variable.get()}') print(self.Correct_Answer)Below is it being called in another class. Moment easy inherits Question if self.ListOfQuestions[i] == 'Moments': realQuestion = MomentEasy() realQuestion.Generate() realQuestion.ShowQuestion()The method ShowQuestion() calls mark when run self.Mark_button = Ctk.CTkButton(self.QuestionWindow, text = 'Mark', command = self.Mark)if i ran the exact same code outside a class it works everytime perfectly The method Mark() is inside a class called Question however when the class is instantiated in another class(QuestionSet) the tkinter entry box always returns a blank string rather than a string of the numbers entered. When the method mark()is called through an instance by itself it works completely fine, the error only occurs when it is called from within another class. Any help is appreciated. Cheers RE: Tkinter callback exception - deanhystad - Feb-16-2024 You need to post an example of this class being accessed through another. RE: Tkinter callback exception - deanhystad - Feb-17-2024 Do not update your original post. Put new information in a new post. If you updated your post to show calling the method different ways, I don't see it. Post a small runnable example that demonstrates the problem. |