2016-11-17 15 views
1
import pygame,sys 
pygame.init() 
pygame.display.set_caption("Magnifying Glasses") 

size = (425,550) 

lightcyan = (191,255,255) 
black = (0,0,0) 
blue = (0,0,255) 
cyan = (127,255,255) 
lightblue = (95,127,255) 

titlefont = pygame.font.SysFont("Calibri",36) 
subtitlefont = pygame.font.SysFont("Calibri",24) 
font = pygame.font.SysFont("Calibri",12) 

def main(): 
    screen = pygame.display.set_mode(size) 

    fadein = pygame.Surface(size) 
    fadein.set_alpha(255) 
    screen_Rect = screen.get_rect() 

    spacing = 18 

    title_Text = titlefont.render("NOW I SEE",1,black,lightcyan) 
    title_TextRect = title_Text.get_rect(center = screen_Rect.center) 
    title_TextRect.center = (title_TextRect.center) 
    title_TextRect.top = 24 

    underline = pygame.Surface((title_TextRect[2],2)) 

    fadein_Alpha = 255 

    page = 4 

    navigation_Y = title_TextRect.bottom + spacing 
    button_Length = (size[0] - spacing - spacing)/4 
    button_Width = button_Length/4 
    button_Color = lightcyan 
    button_LineColor = black 
    LEFT = 1 

    home_Rect = pygame.Rect(spacing,navigation_Y,button_Length,button_Width) 
    background_Rect = pygame.Rect(home_Rect.right,navigation_Y,button_Length,button_Width) 
    refraction_Rect = pygame.Rect(background_Rect.right,navigation_Y,button_Length,button_Width) 
    interact_Rect = pygame.Rect(refraction_Rect.right,navigation_Y,button_Length,button_Width) 

    home_Text = font.render("Home",1,button_LineColor) 
    background_Text = font.render("Background",1,button_LineColor) 
    refraction_Text = font.render("Refraction",1,button_LineColor) 
    interact_Text = font.render("Interact",1,button_LineColor) 

    home_TextRect = home_Text.get_rect(center = home_Rect.center) 
    background_TextRect = background_Text.get_rect(center = background_Rect.center) 
    refraction_TextRect = refraction_Text.get_rect(center = refraction_Rect.center) 
    interact_TextRect = interact_Text.get_rect(center = interact_Rect.center) 

    def home(): 
     global font 

     line1 = font.render(" Have you ever looked at something small under a magnifying glass (for",1,black) 
     line2 = font.render("example, bugs, small writing). The object (or objects) you are looking at",1,black) 
     line3 = font.render("appear much larger than they actually are. This is because a magnifying glass",1,black) 
     line4 = font.render("is composed of a lens. Lenses are curved pieces of glass that change the",1,black) 
     line5 = font.render("appearance of objects when you look through them. Lenses come in two",1,black) 
     line6 = font.render("varieties:",1,black) 

     rect1 = line1.get_rect(topleft = (spacing,home_Rect.bottom + spacing)) 
     rect2 = line2.get_rect(topleft = (spacing,rect1.bottom)) 
     rect3 = line3.get_rect(topleft = (spacing,rect2.bottom)) 
     rect4 = line4.get_rect(topleft = (spacing,rect3.bottom)) 
     rect5 = line5.get_rect(topleft = (spacing,rect4.bottom)) 
     rect6 = line6.get_rect(topleft = (spacing,rect5.bottom)) 

     magnifyingglass = pygame.image.load("Magnifying Glass.png") 
     magnifyingglass_Rect = magnifyingglass.get_rect(topleft = (spacing,rect6.bottom + spacing)) 

     convex = font.render("Convex: ",1,black) 
     convex_Desc = font.render("(left)",1,black) 
     convex_Rect = convex.get_rect(topleft = (magnifyingglass_Rect.right + spacing,rect6.bottom + spacing)) 
     convex_DescRect = convex_Desc.get_rect(topleft = (magnifyingglass_Rect.right + spacing,convex_Rect.bottom)) 

     line7 = font.render("Convex lenses are lenses that",1,black) 
     line8 = font.render("are thickest near the centre.",1,black) 
     line9 = font.render("When light enters this lens",1,black) 
     line10 = font.render("it converges, then diverges.",1,black) 
     line11 = font.render("The characteristics of the",1,black) 
     line12 = font.render("image may vary.",1,black) 

     rect7 = line7.get_rect(topleft = (convex_Rect.right,rect6.bottom + spacing)) 
     rect8 = line8.get_rect(topleft = (convex_Rect.right,rect7.bottom)) 
     rect9 = line9.get_rect(topleft = (convex_Rect.right,rect8.bottom)) 
     rect10 = line10.get_rect(topleft = (convex_Rect.right,rect9.bottom)) 
     rect11 = line11.get_rect(topleft = (convex_Rect.right,rect10.bottom)) 
     rect12 = line12.get_rect(topleft = (convex_Rect.right,rect11.bottom)) 

     concave = font.render("Concave: ",1,black) 
     concave_Desc = font.render("(right)",1,black) 
     concave_Rect = concave.get_rect(topleft = (magnifyingglass_Rect.right + spacing,rect12.bottom + spacing)) 
     concave_DescRect = concave_Desc.get_rect(topleft = (magnifyingglass_Rect.right + spacing,concave_Rect.bottom)) 

     line13 = font.render("Concave lenses are lenses",1,black) 
     line14 = font.render("that are thinnest near the",1,black) 
     line15 = font.render("centre. When light enters",1,black) 
     line16 = font.render("this lens, it diverges. The",1,black) 
     line17 = font.render("image is always upright and",1,black) 
     line18 = font.render("smaller than the object.",1,black) 

     rect13 = line13.get_rect(topleft = (concave_Rect.right,rect12.bottom + spacing)) 
     rect14 = line14.get_rect(topleft = (concave_Rect.right,rect13.bottom)) 
     rect15 = line15.get_rect(topleft = (concave_Rect.right,rect14.bottom)) 
     rect16 = line16.get_rect(topleft = (concave_Rect.right,rect15.bottom)) 
     rect17 = line16.get_rect(topleft = (concave_Rect.right,rect16.bottom)) 
     rect18 = line16.get_rect(topleft = (concave_Rect.right,rect17.bottom)) 

     rect7.left = concave_Rect.right 
     rect8.left = concave_Rect.right 
     rect9.left = concave_Rect.right 
     rect10.left = concave_Rect.right 
     rect11.left = concave_Rect.right 
     rect12.left = concave_Rect.right 

     convex_Img = pygame.image.load("Convex.png") 
     concave_Img = pygame.image.load("Concave.png") 

     convex_ImgRect = convex_Img.get_rect(topleft = (spacing,magnifyingglass_Rect.bottom + spacing)) 
     concave_ImgRect = concave_Img.get_rect(topright = (size[0] - spacing,magnifyingglass_Rect.bottom + spacing)) 

     screen.blit(line1,rect1) 
     screen.blit(line2,rect2) 
     screen.blit(line3,rect3) 
     screen.blit(line4,rect4) 
     screen.blit(line5,rect5) 
     screen.blit(line6,rect6) 

     screen.blit(magnifyingglass,magnifyingglass_Rect) 

     screen.blit(convex,convex_Rect) 
     screen.blit(convex_Desc,convex_DescRect) 
     screen.blit(line7,rect7) 
     screen.blit(line8,rect8) 
     screen.blit(line9,rect9) 
     screen.blit(line10,rect10) 
     screen.blit(line11,rect11) 
     screen.blit(line12,rect12) 

     screen.blit(concave,concave_Rect) 
     screen.blit(concave_Desc,concave_DescRect) 
     screen.blit(line13,rect13) 
     screen.blit(line14,rect14) 
     screen.blit(line15,rect15) 
     screen.blit(line16,rect16) 
     screen.blit(line17,rect17) 
     screen.blit(line18,rect18) 

     screen.blit(convex_Img,convex_ImgRect) 
     screen.blit(concave_Img,concave_ImgRect) 

    def background(): 
     global font 

     line1 = font.render(" Lenses were created from as early as 750 BC in the Middle East (The British",1,black) 
     line2 = font.render("Museum, n.d.). In 1021, a man named Ibn Al-Haytham published the 'Book of",1,black) 
     line3 = font.render("Optics', which described the use of a lens to magnify objects (Adam-Carr,",1,black) 
     line4 = font.render("2010). The magnifying glass was later used in 1250, by English philosopher",1,black) 
     line5 = font.render("Roger Bacon (Kashner, 2006).",1,black) 

     rect1 = line1.get_rect(topleft = (spacing,home_Rect.bottom + spacing)) 
     rect2 = line2.get_rect(topleft = (spacing,rect1.bottom)) 
     rect3 = line3.get_rect(topleft = (spacing,rect2.bottom)) 
     rect4 = line4.get_rect(topleft = (spacing,rect3.bottom)) 
     rect5 = line5.get_rect(topleft = (spacing,rect4.bottom)) 

     line6 = font.render(" Magnifying glasses are capable of provide quick, weak magnification. When",1,black) 
     line7 = font.render("compared to a microscope or telescope, a magnifying glass is lighter, simpler,",1,black) 
     line8 = font.render("and easier to use; however, it can only magnify objects already visible to the",1,black) 
     line9 = font.render("human eye. Another downside to the magnifying glass is its inability to",1,black) 
     line10 = font.render("magnify objects further/larger than several metres. The use of a telescope is",1,black) 
     line11 = font.render("more suitable for this role.",1,black) 

     rect6 = line6.get_rect(topleft = (spacing,rect5.bottom + spacing)) 
     rect7 = line7.get_rect(topleft = (spacing,rect6.bottom)) 
     rect8 = line8.get_rect(topleft = (spacing,rect7.bottom)) 
     rect9 = line9.get_rect(topleft = (spacing,rect8.bottom)) 
     rect10 = line10.get_rect(topleft = (spacing,rect9.bottom)) 
     rect11 = line11.get_rect(topleft = (spacing,rect10.bottom)) 

     line12 = font.render(" Because of these traits, magnifying glasses may be used in fields of science",1,black) 
     line13 = font.render("such as biology, forensic science, archaeology, and more.",1,black) 

     rect12 = line12.get_rect(topleft = (spacing,rect11.bottom + spacing)) 
     rect13 = line13.get_rect(topleft = (spacing,rect12.bottom)) 

     line14 = font.render("Below are several common terms used to describe a convex lens:",1,black) 
     line15 = font.render("Optical Centre (O): The point located in the centre of a lens",1,black) 
     line16 = font.render("Principal Focus (F): The point at which oncoming light rays parallel to the",1,black) 
     line17 = font.render("principal axis intersect",1,black) 
     line18 = font.render("Secondary Focus (F'): The point symmetrical to F on the axis of symmetry",1,black) 
     line19 = font.render("Axis of Symmetry: The line of symmetry drawn through the side view of a lens",1,black) 
     line20 = font.render("Principal Axis: The line perpendicular to the axis of symmetry, that passes",1,black) 
     line21 = font.render("through O",1,black) 
     note = font.render("Note: ",1,black) 
     line22 = font.render("2F and 2F' indicates the points that are 2× further from the lens than F",1,black) 
     line23 = font.render("and F' respectively.",1,black) 

     rect14 = line14.get_rect(topleft = (spacing,rect13.bottom + spacing)) 
     rect15 = line15.get_rect(topleft = (spacing,rect14.bottom + spacing)) 
     rect16 = line16.get_rect(topleft = (spacing,rect15.bottom)) 
     rect17 = line17.get_rect(topleft = (spacing + 96,rect16.bottom)) 
     rect18 = line19.get_rect(topleft = (spacing,rect17.bottom)) 
     rect19 = line21.get_rect(topleft = (spacing,rect18.bottom)) 
     rect20 = line22.get_rect(topleft = (spacing,rect19.bottom)) 
     rect21 = line23.get_rect(topleft = (spacing + 72,rect20.bottom)) 
     note_Rect = note.get_rect(topleft = (spacing,rect21.bottom + spacing)) 
     rect22 = line19.get_rect(topleft = (note_Rect.right,rect21.bottom + spacing)) 
     rect23 = line20.get_rect(topleft = (note_Rect.right,rect22.bottom)) 

     screen.blit(line1,rect1) 
     screen.blit(line2,rect2) 
     screen.blit(line3,rect3) 
     screen.blit(line4,rect4) 
     screen.blit(line5,rect5) 

     screen.blit(line6,rect6) 
     screen.blit(line7,rect7) 
     screen.blit(line8,rect8) 
     screen.blit(line9,rect9) 
     screen.blit(line10,rect10) 
     screen.blit(line11,rect11) 

     screen.blit(line12,rect12) 
     screen.blit(line13,rect13) 

     screen.blit(line14,rect14) 
     screen.blit(line15,rect15) 
     screen.blit(line16,rect16) 
     screen.blit(line17,rect17) 
     screen.blit(line18,rect18) 
     screen.blit(line19,rect19) 
     screen.blit(line20,rect20) 
     screen.blit(line21,rect21) 
     screen.blit(note,note_Rect) 
     screen.blit(line22,rect22) 
     screen.blit(line23,rect23) 
    def refraction(): 
     global font 

     refraction_Img = pygame.image.load("Refraction.png") 
     refraction_ImgRect = refraction_Img.get_rect(topright = (size[0] - spacing,home_Rect.bottom + spacing)) 

     line1 = font.render(" Refraction is the bending of light when it",1,black) 
     line2 = font.render("passes from one medium (transparent",1,black) 
     line3 = font.render("material) to another. You can experience",1,black) 
     line4 = font.render("this phenomenon when you look through",1,black) 
     line5 = font.render("water. By looking down in a swimming pool,",1,black) 
     line6 = font.render("you can notice that the things you see are",1,black) 
     line7 = font.render("actually deeper than they appear. When",1,black) 
     line8 = font.render("light bounces of the object(s) in the water",1,black) 
     line9 = font.render("and reaches the surface, the angle at which",1,black) 
     line10 = font.render("it travels changes, and you see the light at",1,black) 
     line11 = font.render("the changed angle.",1,black) 

     rect1 = line1.get_rect(topleft = (spacing,home_Rect.bottom + spacing)) 
     rect2 = line2.get_rect(topleft = (spacing,rect1.bottom)) 
     rect3 = line3.get_rect(topleft = (spacing,rect2.bottom)) 
     rect4 = line4.get_rect(topleft = (spacing,rect3.bottom)) 
     rect5 = line5.get_rect(topleft = (spacing,rect4.bottom)) 
     rect6 = line6.get_rect(topleft = (spacing,rect5.bottom)) 
     rect7 = line7.get_rect(topleft = (spacing,rect6.bottom)) 
     rect8 = line8.get_rect(topleft = (spacing,rect7.bottom)) 
     rect9 = line9.get_rect(topleft = (spacing,rect8.bottom)) 
     rect10 = line10.get_rect(topleft = (spacing,rect9.bottom)) 
     rect11 = line11.get_rect(topleft = (spacing,rect10.bottom)) 

     line12 = font.render(" Light travels at different speeds in",1,black) 
     line13 = font.render("different media. Depending on the 1st and",1,black) 
     line14 = font.render("2nd media, light will refract towards/away from the normal. The normal is the",1,black) 
     line15 = font.render("line drawn through the point that light refracts. It is perpendicular to the",1,black) 
     line16 = font.render("border between the two media. If light travels slower in the 1st medium, it will",1,black) 
     line17 = font.render("refract away from the normal (top). If light travels faster in the 1st medium, it",1,black) 
     line18 = font.render("will refract towards the normal (bottom).",1,black) 

     rect12 = line12.get_rect(topleft = (spacing,rect11.bottom + spacing)) 
     rect13 = line13.get_rect(topleft = (spacing,rect12.bottom)) 
     rect14 = line14.get_rect(topleft = (spacing,rect13.bottom)) 
     rect15 = line15.get_rect(topleft = (spacing,rect14.bottom)) 
     rect16 = line15.get_rect(topleft = (spacing,rect15.bottom)) 
     rect17 = line15.get_rect(topleft = (spacing,rect16.bottom)) 
     rect18 = line15.get_rect(topleft = (spacing,rect17.bottom)) 

     line19 = font.render("A lens is designed to control refraction to our advantage. The curvature is",1,black) 
     line20 = font.render("created to make light converge/diverge during entry and exit of the lens. In the",1,black) 
     line21 = font.render("case of a magnifying glass' convex lens, light is directed towards the principal",1,black) 
     line22 = font.render("focus once when it enters the glass, and again when it exits the glass.",1,black) 

     rect19 = line14.get_rect(topleft = (spacing,rect18.bottom + spacing)) 
     rect20 = line15.get_rect(topleft = (spacing,rect19.bottom)) 
     rect21 = line15.get_rect(topleft = (spacing,rect20.bottom)) 
     rect22 = line15.get_rect(topleft = (spacing,rect21.bottom)) 

     convexrefraction = pygame.image.load("Convex Refraction.png") 
     convexrefraction_Rect = convexrefraction.get_rect(midtop = (size[0]/2,rect22.bottom + spacing)) 

     screen.blit(refraction_Img,refraction_ImgRect) 

     screen.blit(line1,rect1) 
     screen.blit(line2,rect2) 
     screen.blit(line3,rect3) 
     screen.blit(line4,rect4) 
     screen.blit(line5,rect5) 
     screen.blit(line6,rect6) 
     screen.blit(line7,rect7) 
     screen.blit(line8,rect8) 
     screen.blit(line9,rect9) 
     screen.blit(line10,rect10) 
     screen.blit(line11,rect11) 

     screen.blit(line12,rect12) 
     screen.blit(line13,rect13) 
     screen.blit(line14,rect14) 
     screen.blit(line15,rect15) 
     screen.blit(line16,rect16) 
     screen.blit(line17,rect17) 
     screen.blit(line18,rect18) 

     screen.blit(line19,rect19) 
     screen.blit(line20,rect20) 
     screen.blit(line21,rect21) 
     screen.blit(line22,rect22) 

     screen.blit(convexrefraction,convexrefraction_Rect) 

    def interact(): 
     global font 

     line1 = font.render(" To determine the qualities of an image, a ray is drawn from the top of the",1,black) 
     line2 = font.render("object parallel to the principal axis (which refracts with respect to F) and",1,black) 
     line3 = font.render("another ray is drawn from the top of the image through the optical centre",1,black) 
     line4 = font.render("(which does not change direction). The top of the image is located where the",1,black) 
     line5 = font.render("two rays intersect. We can then determine the size, attitude, location, and",1,black) 
     line6 = font.render("type of the image produced.",1,black) 

     rect1 = line1.get_rect(topleft = (spacing,home_Rect.bottom + spacing)) 
     rect2 = line2.get_rect(topleft = (spacing,rect1.bottom)) 
     rect3 = line3.get_rect(topleft = (spacing,rect2.bottom)) 
     rect4 = line4.get_rect(topleft = (spacing,rect3.bottom)) 
     rect5 = line5.get_rect(topleft = (spacing,rect4.bottom)) 
     rect6 = line6.get_rect(topleft = (spacing,rect5.bottom)) 

     location_Line = pygame.Surface((size[0] - spacing - spacing,2)) 

     location_Y = rect6.bottom + spacing 
     location_Length = (size[0] - spacing - spacing)/6 
     location_Width = location_Length/4 
     location_Radius = spacing/2 
     location_Color = lightcyan 
     location_LineColor = black 
     LEFT = 1 

     beyond2F_Rect = pygame.Rect(spacing,location_Y,location_Length,location_Width) 
     2F_Rect = pygame.Rect(beyond2F_Rect.right,location_Y,location_Length,location_Width) 
     between2FF_Rect = pygame.Rect(2F_Rect.right,location_Y,location_Length,location_Width) 
     F_Rect = pygame.Rect(between2FF_Rect.right,location_Y,location_Length,location_Width) 
     betweenFO_Rect = pygame.Rect(F_Rect.right,location_Y,location_Length,location_Width) 

     beyond2F_Text = font.render("←",1,location_Color) 
     2F_Text = font.render("2F",1,location_LineColor) 
     between2FF_Text = font.render("↔",1,location_LineColor) 
     F_Text = font.render("F",1,location_LineColor) 
     betweenFO_Text = font.render("→",1,location_LineColor) 

     beyond2F_TextRect = beyond2F_Text.get_rect(center = beyond2F_Rect.center) 
     2F_TextRect = 2F_Text.get_rect(center = 2F_Rect.center) 
     between2FF_TextRect = between2FF_Text.get_rect(center = between2FF_Rect.center) 
     F_TextRect = F_Text.get_rect(center = F_Rect.center) 
     betweenFO_TextRect = betweenFO_Text.get_rect(center = betweenFO_Rect.center) 

     for event in pygame.event.get(): 
      if event.type == pygame.MOUSEBUTTONDOWN: 
       if event.button == LEFT: 
        mouse_Pos = pygame.mouse.get_pos() 
        if home_Rect.collidepoint(mouse_Pos): 
         page = 1 
        elif background_Rect.collidepoint(mouse_Pos): 
         page = 2 
        elif refraction_Rect.collidepoint(mouse_Pos): 
         page = 3 
        elif interact_Rect.collidepoint(mouse_Pos): 
         page = 4 

     line7 = font.render("----",1,black) 
     line8 = font.render("----",1,black) 
     line9 = font.render("----",1,black) 
     line10 = font.render("----",1,black) 
     line11 = font.render("----",1,black) 
     line12 = font.render("----",1,black) 
     line13 = font.render("----",1,black) 
     line14 = font.render("----",1,black) 
     line15 = font.render("----",1,black) 
     line16 = font.render("----",1,black) 
     line17 = font.render("----",1,black) 
     line18 = font.render("----",1,black) 

     rect7 = line7.get_rect(topleft = (spacing,rect6.bottom)) 
     rect8 = line8.get_rect(topleft = (spacing,rect7.bottom)) 
     rect9 = line9.get_rect(topleft = (spacing,rect8.bottom)) 
     rect10 = line10.get_rect(topleft = (spacing,rect9.bottom)) 
     rect11 = line11.get_rect(topleft = (spacing,rect10.bottom)) 
     rect12 = line12.get_rect(topleft = (spacing,rect11.bottom + spacing)) 
     rect13 = line13.get_rect(topleft = (spacing,rect12.bottom)) 
     rect14 = line14.get_rect(topleft = (spacing,rect13.bottom)) 
     rect15 = line15.get_rect(topleft = (spacing,rect14.bottom)) 
     rect16 = line15.get_rect(topleft = (spacing,rect15.bottom)) 
     rect17 = line15.get_rect(topleft = (spacing,rect16.bottom)) 
     rect18 = line15.get_rect(topleft = (spacing,rect17.bottom)) 

     line19 = font.render("----",1,black) 
     line20 = font.render("----",1,black) 
     line21 = font.render("----",1,black) 
     line22 = font.render("----",1,black) 

     rect19 = line14.get_rect(topleft = (spacing,rect18.bottom + spacing)) 
     rect20 = line15.get_rect(topleft = (spacing,rect19.bottom)) 
     rect21 = line15.get_rect(topleft = (spacing,rect20.bottom)) 
     rect22 = line15.get_rect(topleft = (spacing,rect21.bottom)) 

     screen.blit(line1,rect1) 
     screen.blit(line2,rect2) 
     screen.blit(line3,rect3) 
     screen.blit(line4,rect4) 
     screen.blit(line5,rect5) 
     screen.blit(line6,rect6) 

     screen.blit(location_Line,(spacing,rect6.bottom + spacing - 1)) 

     screen.blit(line7,rect7) 
     screen.blit(line8,rect8) 
     screen.blit(line9,rect9) 
     screen.blit(line10,rect10) 
     screen.blit(line11,rect11) 
     screen.blit(line12,rect12) 
     screen.blit(line13,rect13) 
     screen.blit(line14,rect14) 
     screen.blit(line15,rect15) 
     screen.blit(line16,rect16) 
     screen.blit(line17,rect17) 
     screen.blit(line18,rect18) 
     screen.blit(line19,rect19) 
     screen.blit(line20,rect20) 
     screen.blit(line21,rect21) 
     screen.blit(line22,rect22) 

    while True: 
     for event in pygame.event.get(): 
      if event.type == pygame.QUIT: 
       pygame.quit() 
       sys.exit() 
      elif event.type == pygame.MOUSEBUTTONDOWN: 
       if event.button == LEFT: 
        mouse_Pos = pygame.mouse.get_pos() 
        if home_Rect.collidepoint(mouse_Pos): 
         page = 1 
        elif background_Rect.collidepoint(mouse_Pos): 
         page = 2 
        elif refraction_Rect.collidepoint(mouse_Pos): 
         page = 3 
        elif interact_Rect.collidepoint(mouse_Pos): 
         page = 4 

     if fadein_Alpha > 0: 
      fadein_Alpha -= 3 
      fadein.set_alpha(fadein_Alpha) 

     screen.fill(lightcyan) 
     fadein.fill(black) 
     screen.blit(title_Text,title_TextRect) 
     screen.blit(underline,(title_TextRect.left,title_TextRect.bottom)) 

     if page == 1: 
      pygame.draw.rect(screen,cyan,home_Rect) 
      pygame.draw.rect(screen,button_Color,background_Rect) 
      pygame.draw.rect(screen,button_Color,refraction_Rect) 
      pygame.draw.rect(screen,button_Color,interact_Rect) 
      home() 
     elif page == 2: 
      pygame.draw.rect(screen,button_Color,home_Rect) 
      pygame.draw.rect(screen,cyan,background_Rect) 
      pygame.draw.rect(screen,button_Color,refraction_Rect) 
      pygame.draw.rect(screen,button_Color,interact_Rect) 
      background() 
     elif page == 3: 
      pygame.draw.rect(screen,button_Color,home_Rect) 
      pygame.draw.rect(screen,button_Color,background_Rect) 
      pygame.draw.rect(screen,cyan,refraction_Rect) 
      pygame.draw.rect(screen,button_Color,interact_Rect) 
      refraction() 
     elif page == 4: 
      pygame.draw.rect(screen,button_Color,home_Rect) 
      pygame.draw.rect(screen,button_Color,background_Rect) 
      pygame.draw.rect(screen,button_Color,refraction_Rect) 
      pygame.draw.rect(screen,cyan,interact_Rect) 
      interact() 

     pygame.draw.rect(screen,button_LineColor,home_Rect,2) 
     pygame.draw.rect(screen,button_LineColor,background_Rect,2) 
     pygame.draw.rect(screen,button_LineColor,refraction_Rect,2) 
     pygame.draw.rect(screen,button_LineColor,interact_Rect,2) 

     screen.blit(home_Text,home_TextRect) 
     screen.blit(background_Text,background_TextRect) 
     screen.blit(refraction_Text,refraction_TextRect) 
     screen.blit(interact_Text,interact_TextRect) 

     screen.blit(fadein,(0,0)) 
     pygame.display.flip() 
     pygame.time.wait(10) 

main() 

私が実行するたびに、IDLEは「無効な構文」を2F_Rect = pygame.Rect(beyond2F_Rect.right,location_Y,location_Length,location_Width)に教えてくれます。どうやら、私が2F_Rect、2F_Text、2F_TextRectの2Fを "apple"や "b2F"(何かランダム)のように変えても、私はエラーにはなりません。誰かが私に説明することができた理由は、変数がその名前に "2F"を持っているため、構文エラーが出るのですか?「無効な構文」エラーが発生するのはなぜですか?

私はコピー&ペーストして、ファイル全体を

+1

を見て、あなたがコピー&ペーストして、ファイル全体を持っていないし、それを回避する方法理由を確認するために[MCVE]読みください理由を見ることができます。現在のケースでは、この1行のPythonプログラム '2F_Rect = 'hello''を書いて、構文エラーがあることを確認し、短い完全なプログラムをコピーして貼り付けることができました。 –

答えて

2

変数が数字で始めることはできませんでした謝罪。

あなたはあなたの次の質問の前に、Pythonのgrammar

関連する問題