i get to down as far as the tax equation and it won't run, any ideas??

from graphics import *

def main():
win=GraphWin("Taxation Calculator",300,240)
win.setCoords(0.0,0.0,3.0,4.0)
#draw interactive entry boxes
Text(Point(1,3),"Salary: ").draw(win)
input=Entry(Point(2,3),5)
input.setText("0000")
Output=Text(Point(2,1)," ")
Output.draw(win)
Button=Text(Point(1.5,2.0), "Calculate Tax")
Button.draw(win)
Rectangle(Point(1,1.5),Point(2,2.5)).draw(win)

#wait for mouse click
win.getMouse()

#convert Tax
amount= eval(input.getText())
if amount <= 20000:
print "you pay no tax"

elif amount > 20000 <= 40000:
tax = (amount /100.0) * 30.0)
print "you pay this amount in tax",tax

elif amount > 40000 <= 80000:
tax =(amount/100.0) * 40.0)
print "you pay this amount in tax",tax

else amount < 80000:
tax =(amount/100.0) * 50.0)
print "you pay this amount in tax",tax

output.setText("%0.1% tax)
button.setText("Quit")
win.getMouse()
win.close()
main()

Dani AI

Generated

This thread contains the key clues. correctly notes that graphics.py is a thin Tkinter wrapper (so widget names and methods may differ from modern Tkinter), and asked for properly posted code and the actual traceback, and spotted a bad output-formatting line. The symptoms reported ("won't run") most often come from a small syntax or logic error that the interpreter will pinpoint if the full traceback is posted.

Checklist of likely problems to inspect (do these before redesigning the GUI):

  • Indentation: the entire function body must be indented consistently; Python enforces it.
  • Unmatched parentheses on the arithmetic lines will raise a SyntaxError; look at the exact traceback line.
  • Condition logic: chained comparisons behave differently than separate tests (use explicit chained form or and to express ranges). See Python comparisons for details.
  • Invalid else usage: else takes no condition — use elif or a final else:.
  • Name and case mismatches: Output vs output and Button vs button are distinct names in Python and cause NameError.
  • Input conversion: avoid eval for user input; use int() or float() inside a try/except to handle bad input safely (see the eval docs).

Practical debugging steps:

  • Run the script from a terminal to capture the full traceback and line numbers.
  • Fix the first SyntaxError reported and re-run; many other errors disappear afterward.
  • Extract the tax calculation into a small pure function, test it in the REPL or with a few unit tests, then hook it into the GUI.
  • Use explicit formatting or the format method (or f-strings on modern Python) to build the display string.

Reference reading: Python comparisons (chained comparisons) and the eval behavior:

Recommended Answers

All 5 Replies

I think it has been said here numerous times, but the module is a subset wrapper for Tkinter from a older book. Not too many folks use it, so help will be difficult to get.

Some college profs use the old graphics module to keep their students honest.

i get to down as far as the tax equation and it won't run, any ideas??

I have an idea, and that idea is "please wrap your program in code tags."

i get to down as far as the tax equation and it won't run,

And you'll have to be more specific. "Won't run" does not say enough and where in hell is the tax equation. Include the error message at the very least (which I am sure is a syntax error, so the question should be, "why do I get this syntax error on this line number in the program").

...where in hell is the tax equation...

Massachusetts.

Seriously, this line:

output.setText("%0.1% tax)

should read

output.setText("%0.1f" % tax)

I think.

Use print statements to figure out where the problem is exactly.

Jeff

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.