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
#2
You need to post an example of this class being accessed through another.
Ben123 likes this post
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter exception if entries are not filled up Reldaing 6 2,435 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,505 Jul-10-2019, 12:48 AM
Last Post: FullOfHelp
  [matpltlib]Basic question about callback function schniefen 3 3,238 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,840 Aug-05-2018, 11:01 PM
Last Post: woooee
  pygtk2, how to disconnect all callback of widget or window event ? harun2525 1 3,317 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