Python Forum
[Tkinter] Tkinter callback exception
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tkinter callback exception
#1
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
Reply


Messages In This Thread
Tkinter callback exception - by Ben123 - Feb-15-2024, 07:02 PM
RE: Tkinter callback exception - by deanhystad - Feb-16-2024, 04:53 AM
RE: Tkinter callback exception - by deanhystad - Feb-17-2024, 06:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter exception if entries are not filled up Reldaing 6 2,484 Jan-09-2020, 05:20 PM
Last Post: Axel_Erfurt
  GUI freezes while executing a callback funtion when a button is pressed abi17124 5 7,563 Jul-10-2019, 12:48 AM
Last Post: FullOfHelp
  [matpltlib]Basic question about callback function schniefen 3 3,270 May-20-2019, 09:47 PM
Last Post: Yoriz
  Unable to return value from callback function of a button in Python Tkinter nilaybnrj 4 20,908 Aug-05-2018, 11:01 PM
Last Post: woooee
  pygtk2, how to disconnect all callback of widget or window event ? harun2525 1 3,365 Feb-19-2017, 11:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020