1

I'm new to Python and just started writing a basic GUI program with wxPython. I have a series of text boxes where the user enters data and then they click a submit button.

The submit button triggers a getvalue method for each box (it looks like a=self.textbox1.GetValue()).

The there is a function that simply reads answer=a+b+c+d+e+f+g+h.

Then finally there's the wx.MessageDialog(self, answer, Title, wx.OK | wx.ICON_EXCLAMATION) that prints the answer in a msg dialog.

But instead of printing the sum of the numbers, it just prints them in a series.

I was messing around and replaced the variables in the answer function with actual integers and it gives me an error that says:

String or Unicode type required

I can't really think of any way to fix it since I only have like two days experience with Python.

How can I fix this?

1 Answer 1

1

GetValue() gives you the string value of what was typed.

You want to convert the strings to integers before trying to sum them.

a = int(self.textbox1.GetValue())
Sign up to request clarification or add additional context in comments.

3 Comments

Now it gives ValueError: could not convert string to float:
Actually that was another part of the code, fixed that, but the message dialog is still giving the same error after I took int values of variables.
You have to convert answer back to a string to display it. str(answer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.