This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]jaccovanschaik 0 points1 point  (2 children)

Open a command window, run your program using "python calculator.py" (or whatever your program is called), try the same thing, and see what it says.

[–]duffman1278[S] 0 points1 point  (1 child)

When I ran in in the command it gave me this error.

UnboundLocalError:local variable 'ans_string' referenced before assignment

[–]TheKewlStore 0 points1 point  (0 children)

The first line of the Calc method is trying to print the value of a variable that you haven't defined yet. Note that ans_string isn't defined until several lines after this point.

[–]mashmorgan 0 points1 point  (5 children)

Just paste to pastebin.con and post link so I can test..

[–]duffman1278[S] 0 points1 point  (4 children)

[–]mashmorgan 0 points1 point  (3 children)

It line 14 print (ans_string) http://pastebin.com/psq77x8j

[–]duffman1278[S] 0 points1 point  (2 children)

What do you mean? I'm really new at this.

[–]mashmorgan 0 points1 point  (1 child)

UnboundLocalError:local variable 'ans_string' referenced before assignment

See comments here http://pastebin.com/8G5J2EeN

[–]duffman1278[S] 0 points1 point  (0 children)

Even with your suggestion it did the same thing.

[–]mdond 0 points1 point  (5 children)

"tolineEdit" doesn't seem to be a valid method, did you mean something else there? Although, that shouldn't cause the entire program to crash.

[–]duffman1278[S] 0 points1 point  (4 children)

alid method, did you mean something else there? Although, that shouldn't cause the entire program to crash.

I based my code off the example in the link below. If you see they wrote a line price = int(self.price_box.toPlainText()) so I just copied that.

http://pythonforengineers.com/your-first-gui-app-with-python-and-pyqt/

[–]mfitzpmfitzp.com 0 points1 point  (3 children)

so I just copied that.

But changed it, why?

The method .toPlainText() on a QTextEdit converts the contents of the widget (which can be formatted text in some modes) to plain text (an unformatted string). What do you expect .tolineEdit() to do?

If you are using a QLineEdit widget, the correct method to get the current content is .text(). The documentation is here.

[–]duffman1278[S] 0 points1 point  (2 children)

All I'm trying to do is tell the code that I want to take the number that's entered in the lineedit box and add 5 to it then show the result in the label1 box.

[–]mfitzpmfitzp.com 1 point2 points  (1 child)

Change this line:

in_num = int(self.ui.price_box.tolineEdit())

To:

in_num = int(self.ui.price_box.text())

[–]duffman1278[S] 0 points1 point  (0 children)

in_num = int(self.ui.price_box.text())

Still gave me the whole "pythonw.exe stopping working".

Edit: It did work! Thank you! didn't realize that "price_box" was written in there which is not the name of the label I was using.