#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    24
    Rep Power
    0

    Program keeps on getting an error


    I have been working on this program using graphics (which I am new to) to search a given text file and input into a graphics interface. However, I cannot find the error in my program. I would really appreciate if I could have some help. Thanks!
    Code:
    from graphics import *
    
    def search():
        win = GraphWin("Weather Search",800,500)
        win.setCoords(0.0,0.0,40.0,100.0)
    
        infile = open("weather_data.txt","r")
        
    
        day = Text(Point(5,85), "Day: ")
        day.setStyle("bold")
        day.setSize(35)
        day.setFill("blue")
        day.draw(win)
    
        d_in = Entry(Point(12,85),6)
        d_in.setText("dd")
        d_in.draw(win)
    
        month = Text(Point(5,65), "Month: ")
        month.setSize(10)
        month.draw(win)
    
        m_in = Entry(Point(12,65),6)
        m_in.setText("mm")
        m_in.draw(win)
    
        year = Text(Point(5,45), "Year: ")
        year.setSize(10)
        year.draw(win)
    
        y_in = Entry(Point(12,45),6)
        y_in.setText("yyyy")
        y_in.draw(win)
    
        button = Text(Point(9,20), "Search Weather")
        button.draw(win)
        Rectangle(Point(1,12), Point(17,26)).draw(win)
      
        avg1 = Text(Point(23,85), "Average Temperature(F): ")
        avg1.setStyle("bold")
        avg1.setSize(10)
        avg1.setFill("blue")
        avg1.draw(win)
    
        maxtemp1=Text(Point(23,65), "Maximum Temperature(F): ")
        maxtemp1.setSize(10)
        maxtemp1.draw(win)
    
        mintemp1=Text(Point(23,45), "Minimum Temperature(F): ")
        mintemp1.setSize(10)
        mintemp1.draw(win)
    
    
        win.getMouse()
    
        m1 = eval(m_in.getText())
        d1 = eval(d_in.getText())
    
    
        for line in (infile):
            
            avg, maxtemp, mintemp, month, day, year = line.split(",")
            if(m1 == month):
                if(d1 == day):
                    return avg, maxtemp, mintemp
                
    
    
        a_out=Text(Point(29,85),avg)
        a_out.draw(win)
    
        maxtemp_out=Text(Point(29,65),maxtemp)
        maxtemp_out.draw(win)
        
        mintemp_out=Text(Point(29,45),mintemp)
        mintemp_out.draw(win)
    
        button.setText("Quit")
    
        win.getMouse()
        infile.close()
        win.close()
    
    search()
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,896
    Rep Power
    481

    What is the symptom???


    ok, I found a "the graphics module" http://mcsp.wartburg.edu/zelle/python/graphics.py
    If this isn't the correct module you'll have to direct us to your non-standard code.


    Now we need your weather_data.txt file.
    infile = open("weather_data.txt","r")

    python3 doesn't complain about syntax errors. The module loads. What is the problem?
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    24
    Rep Power
    0
    i keeping getting the error "SyntaxError: invalid token". and this is my txt file below
    Code:
    70, 74, 65, 09, 21, 2013
    69, 81, 57, 09, 22, 2013
    69, 82, 56, 09, 23, 2013
    69, 72, 66, 09, 24, 2013
    66, 67, 64, 09, 25, 2013
    71, 80, 61, 09, 26, 2013
    69, 80, 58, 09, 27, 2013
    66, 77, 55, 09, 28, 2013
    65, 76, 53, 09, 29, 2013
    65, 77, 53, 09, 30, 2013
    69, 82, 55, 10, 01, 2013
    70, 83, 56, 10, 02, 2013
    73, 84, 62, 10, 03, 2013
    72, 85, 59, 10, 04, 2013
    73, 86, 60, 10, 05, 2013
    72, 84, 60, 10, 06, 2013
    65, 73, 56, 10, 07, 2013
    65, 75, 55, 10, 08, 2013
    66, 76, 56, 10, 09, 2013
    66, 79, 52, 10, 10, 2013
    67, 79, 54, 10, 11, 2013
    67, 80, 54, 10, 12, 2013
    69, 83, 54, 10, 13, 2013
    69, 76, 61, 10, 14, 2013
    64, 69, 59, 10, 15, 2013
    65, 75, 55, 10, 16, 2013
    66, 71, 61, 10, 17, 2013
    62, 71, 52, 10, 18, 2013
    59, 64, 54, 10, 19, 2013
    57, 70, 44, 10, 20, 2013
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,896
    Rep Power
    481
    Program works on my computer.
    Install linux. Discard everything else.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    24
    Rep Power
    0
    im currently using python to run my program and i keep getting the same error. so i went to check my code again and again, and i can't seem to find the error I may have forgotten. Is there any spacing issues i have or anything?
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,896
    Rep Power
    481
    fool me twice, shame on me.


    Originally Posted by me
    What is the problem?
    Originally Posted by you, more recently
    i keep getting the same error.
    end of thread.
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    24
    Rep Power
    0
    It keeps saying that I have a Syntax Error: Invalid token

IMN logo majestic logo threadwatch logo seochat tools logo