Example #1
0
def Newtons_First_Law(main_window, menuclip, typing_clip, music_playing):

    global clip, musicname, helproot_exist
    root = Toplevel()
    methods.centralise(root, 950, 600)
    root.resizable(0, 0)
    root.title("NEWTON'S FIRST LAW OF MOTION")
    root.iconbitmap("images/newticon.ico")
    musicname = 'sounds/ambient.mp3'
    clip = mp3play.load(musicname)
    clip2 = mp3play.load('sounds/meteor.mp3')
    clip.play()
    # Ask User whether wants to exit or not

    def on_closing():
        if tkMessageBox.askokcancel("Quit", "Do you want to go back to Main Menu?"):
            back()
    root.protocol("WM_DELETE_WINDOW", on_closing)

    #() Animation Frame
    container = Frame(root, bg='royalblue4')
    container.pack(side=TOP, fill="both", expand=True)

    #(1) Button Frame
    buttonframe = Frame(root, height=34, bg='royalblue4')
    buttonframe.pack(side=BOTTOM, fill="both", expand=False)

    #(3) Pygame Frame
    pyg_width = 950
    half_pyg_width = pyg_width / 2
    pyg_height = 400
    half_pyg_height = pyg_height / 2
    embed = Frame(root, width=500, height=200, bg='black')
    embed.pack(expand=True, fill=BOTH)

    root.update()

    # insert pygame into Pygame Frame
    os.environ['SDL_WINDOWID'] = str(embed.winfo_id())

    if sys.platform == "win32":
        os.environ['SDL_VIDEODRIVER'] = 'windib'

    pygame.display.init()

    screen = pygame.display.set_mode((pyg_width, pyg_height))
    space = pygame.image.load('images/space1.gif')

    # placing big rock
    image = pygame.image.load('images/big_meteor.png')
    image = pygame.transform.scale(image, (70, 95))
    big_rock = Rock(image)

    # placing small rock
    image = pygame.image.load('images/big_meteor.png')
    image = pygame.transform.scale(image, (35, 47))
    image = pygame.transform.rotate(image, -85)
    small_rock = Rock(image)

    clock = pygame.time.Clock()
    fps = 60

    def move_for_collision():
        anime_button.config(state=DISABLED, fg="grey", bg="lightblue2")
        reset_button.config(state=DISABLED, fg="grey", bg="lightblue2")
        pop_up = "Let us assume the big meteor is stationary, and the small meteor is going to exert an external force on it."
        typewriter(pop_up, 30)
        waitforcontinue()
        new_button.destroy()
        colliding = True
        stepx = (big_rock.rect.centerx - small_rock.rect.centerx) / 60
        stepy = (big_rock.rect.centery - small_rock.rect.centery) / 60

        stepx *= 0.2
        stepy *= 0.3
        reversestepx = stepx * 0.5
        reversestepy = stepy * 0.0
        bigstepx = stepx * 0.45
        bigstepy = stepy * 0.35
        n = 1
        smallturn = 0.0
        bigturn = 0.0
        big_rock.refresh()
        small_rock.refresh()
        new_rect = small_rock.rect.copy()
        while colliding:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    colliding = False
                    after_collision = False
            if pygame.sprite.collide_rect(small_rock, big_rock):
                colliding = False
                after_collision = True
                clip2.play()
            if (small_rock.rect.centerx > big_rock.rect.centerx / 2) and (n < 2):
                typing_clip.stop()
                pop_up2 = "Once an external force is exerted on the big stationary meteor, it moves. "
                typewriter(pop_up2, 30)
                waitforcontinue()
                n += 1
            small_rock.movex = stepx
            small_rock.movey = stepy
            smallturn -= 0.3
            small_rock.update(smallturn)
            screen.blit(space, [0, -500])
            screen.blit(big_rock.image, big_rock.rect)
            small_rock_turned = pygame.transform.rotate(
                small_rock.image, small_rock.angle)
            screen.blit(small_rock_turned, small_rock.rect)
            clock.tick(fps)
            pygame.display.update()

        while after_collision:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    colliding = False
                    after_collision = False
            if big_rock.rect.centerx > pyg_width:
                after_collision = False
            small_rock.movex = -reversestepx
            small_rock.movey = -reversestepy
            smallturn -= 0.07
            small_rock.update(smallturn)
            big_rock.movex = bigstepx
            big_rock.movey = bigstepy
            bigturn -= 0.06
            big_rock.update(bigturn)
            screen.blit(space, [0, -500])
            small_rock_turned = pygame.transform.rotate(
                small_rock.image, small_rock.angle)
            screen.blit(small_rock_turned, small_rock.rect)
            big_rock_turned = pygame.transform.rotate(
                big_rock.image, big_rock.angle)
            screen.blit(big_rock_turned, big_rock.rect)
            clock.tick(fps)
            pygame.display.update()

        reset_button.config(state=NORMAL, fg="white", bg="royalblue4")
        anime_button.config(state=DISABLED, fg="grey", bg="lightblue2")

    def reset():
        reset_button.config(state=DISABLED, fg="grey", bg="lightblue2")
        screen.blit(space, [0, -500])

        big_rock.rect.centerx = half_pyg_width
        big_rock.rect.centery = half_pyg_height
        screen.blit(big_rock.image, big_rock.rect)

        small_rock.rect.centerx = 100
        small_rock.rect.centery = 100
        screen.blit(small_rock.image, small_rock.rect)

        anime_button.config(state=NORMAL, fg="white", bg="royalblue4")
        pygame.display.update()

    anime_button = Button(buttonframe, text="Begin Animation", relief=RAISED,
                          font=("Comic Sans MS", 12), fg='royalblue4',
                          bg="lightblue2", bd=5,
                          height=1, command=move_for_collision)
    anime_button.pack(side=LEFT, fill=BOTH, expand=True)

    reset_button = Button(buttonframe, text="Reset", relief=RAISED,
                          font=("Comic Sans MS", 12), fg='royalblue4',
                          bg="lightblue2", bd=5, state='disabled',
                          height=1, command=reset)
    reset_button.pack(side=LEFT, fill=BOTH, expand=True)
    reset()

    # Def Main Menu Button

    def back():
        pygame.display.quit()
        typing_clip.stop()
        clip.stop()
        try:
            helproot
        except NameError:
            helproot_exists = False
        else:
            helproot_exists = True

        if helproot_exists:
            helproot.destroy()
        root.destroy()
        main_window.deiconify()
        methods.type(main_window, menuclip, typing_clip, music_playing)

    # Def Help Button

    def helpme():
        global helproot
        try:
            helproot
        except NameError:
            helproot = methods.helpwindow(root, 1)
        else:
            if helproot.winfo_exists() == 0:
                helproot = methods.helpwindow(root, 1)
            else:
                helproot.deiconify()

    # Def Music On:

    def musicon():
        clip.play()
        music_on.config(state=DISABLED, fg="grey")
        music_off.config(state=NORMAL, fg="royalblue4")

    # Def Music Off:

    def musicoff():
        clip.stop()
        music_on.config(state=NORMAL, fg="royalblue4")
        music_off.config(state=DISABLED, fg="grey")

    # #Buttons
    back_btn = Button(container, text="Main Menu", relief=RAISED,
                      font=("Comic Sans MS", 12), fg='royalblue4',
                      bg="lightblue2", bd=5, command=back)
    back_btn.place(relx=0.91, rely=0.22, anchor=CENTER)

    helpbut = Button(container, text="Help", relief=RAISED,
                     font=("Comic Sans MS", 12), fg='royalblue4',
                     bg="lightblue2", bd=5, command=helpme)
    helpbut.place(relx=0.81, rely=0.22, anchor=CENTER)

    music_on = Button(container, text="ON", command=musicon, width=4,
                      font=("Comic Sans MS bold", 10), relief=RAISED,
                      fg='royalblue4', bg="lightblue2", bd=3, state="disabled")
    music_on.place(relx=0.07, rely=0.31, anchor=CENTER)

    music_off = Button(container, text="OFF", command=musicoff, width=5,
                       font=("Comic Sans MS bold", 10), relief=RAISED,
                       fg='royalblue4', bg="lightblue2", bd=3)
    music_off.place(relx=0.125, rely=0.31, anchor=CENTER)

    # Labels
    deftext = Label(root, text="Theory: An object will continue its state of motion (stationary/ constant velocity) unless an external force acts on it!",
                    relief=SUNKEN, fg='white', bg='royalblue4',
                    font=("Comic Sans MS", 12), wraplength=900, bd=5)
    deftext.place(relx=0.5, rely=0.155, anchor=CENTER)

    titletext = Label(root, text="NEWTON'S FIRST LAW OF MOTION", fg='white', width=32,
                      relief=SUNKEN, font=("Comic Sans MS bold", 20),  bd=5, bg='royalblue4')
    titletext.place(relx=0.475, rely=0.07, anchor=CENTER)

    music_label = Label(container, text="Music Status:", font=("Comic Sans MS", 11),
                        fg="white", bg="royalblue4", bd=5, height=1)
    music_label.place(relx=0.1, rely=0.13, anchor=CENTER)

    # Typewriter label
    message = Label(container, fg='white', font=("Comic Sans MS", 12), relief='ridge', bd=5,
                    bg='steelblue', text="", anchor=W, wraplength=700, justify=LEFT, width=79, height=2)
    message.place(relx=0.065, rely=0.66)

    def waitforcontinue():
        global new_button
        var = BooleanVar()
        new_button = Button(root, bd=5,
                            bg='royalblue4', fg='white', font=("Comic Sans MS", 12), text="Next",
                            command=lambda: var.set(True))
        new_button.place(relx=0.83, rely=0.205)
        new_button.wait_variable(var)
        new_button.destroy()

    def typewriter(text, delay):
        typing_clip.play()

        def wait():
            var = IntVar()
            root.after(delay, var.set, 1)
            root.wait_variable(var)
        message_text = text
        message_display = ""

        for letter in message_text:
            message_display += letter
            wait()
            message.configure(text=message_display)
        typing_clip.stop()

    counter = 0
    if counter == 0:
        # Typewriter
        reset_button.config(state=DISABLED, fg="grey", bg="lightblue2")
        anime_button.config(state=DISABLED, fg="grey", bg="lightblue2")
        pygame.display.update()
        first_instruction = "Hi, welcome to Newton's First Law of Motion, in this section, Newt will be guiding you through the definition of the First Law."
        typewriter(first_instruction, 30)
        waitforcontinue()
        pygame.display.update()

        second_instruction = "Isaac Newton states that an object will continue its state of motion unless a force acts on it."
        typewriter(second_instruction, 30)
        waitforcontinue()
        pygame.display.update()

        third_instruction = "Click the Begin Animation button to start."
        typewriter(third_instruction, 30)
        waitforcontinue()
        pygame.display.update()
        if big_rock.rect.centerx < pyg_width:
            reset_button.config(state=DISABLED, fg="grey", bg="lightblue2")
            anime_button.config(state=NORMAL, fg="white", bg="royalblue4")
        pygame.display.update()
        counter += 1

    root.mainloop()
Example #2
0
def Newtons_Second_Law(main_window, menuclip, typing_clip, music_playing):
    global tries, stick, ball, balls, clip, musicname
    tries = 1

    OFFWHITE = 'lemonchiffon'
    TEXTBROWS = 'saddlebrown'
    FONTFAMILY = "Comic Sans MS"

    root2 = Toplevel()
    methods.centralise(root2, 900, 600)
    root2.resizable(0, 0)
    root2.title("NEWTON'S SECOND LAW OF MOTION")
    root2.iconbitmap("images/newticon.ico")
    root2.configure(bg='royalblue4')
    musicname = 'sounds/cool.mp3'
    clip = mp3play.load(musicname)
    clip.play()

    def on_closing():
        if tkMessageBox.askokcancel("Quit",
                                    "Do you want to go back to Main Menu?"):
            back()

    root2.protocol("WM_DELETE_WINDOW", on_closing)

    def acceleration(F, f):
        global Force, friction
        Force = F
        friction = f
        F -= f
        acc = F / 0.16
        return acc

    def velocity(acc, t):
        v = acc * t
        return v

    def displacement(vel, acc, t):
        global decc, dist_1, dist_2, dist_2_time, total_dist
        dist_1 = (0.5) * (acc) * (t**2)
        decc = 2 / 0.16
        dist_2 = (-(vel**2)) / (2 * (-decc))
        dist_2_time = (-vel) / (-decc)
        total_dist = dist_1 + dist_2
        return total_dist

    def wait_for_continue():
        global new_button

        var = BooleanVar()
        new_button = Button(root2,
                            bd=5,
                            bg='royalblue4',
                            fg='white',
                            font=("Comic Sans MS", 12),
                            text="Next",
                            command=lambda: var.set(True))
        new_button.place(relx=0.876, rely=0.58)
        new_button.wait_variable(var)
        new_button.destroy()

    def explain():

        screen.blit(zoomed_expl, [0, 0])
        screen.blit(v_arrow, [450, 50])
        screen.blit(v_arrow, [500, 50])

        force = Forcefont.render('F = ' + str(Force) + 'N', True, (0, 0, 0))
        forceRect = force.get_rect()
        frictionfont = pygame.font.Font('images/ARLRDBD.ttf', 22)
        friction_text = frictionfont.render('f = ' + str(friction) + 'N', True,
                                            (0, 0, 0))
        frictionRect = friction_text.get_rect()
        screen.blit(force, [450, 10])
        screen.blit(friction_text, [265, 103])
        screen.blit(f_arrow, [225, 110])
        pygame.display.update()
        instruction = "The Force applied by the Stick is " + str(
            Force) + "N. The friction is " + str(
                friction
            ) + "N. Hence, the ball experiences a net forward Force of " + str(
                Force - friction) + "N."
        typewriter(instruction, 20)
        wait_for_continue()

        instruction = "The mass of the ball is 0.16kg. Obeying ' F = m x a ': The acceleration is " + \
            str(acc) + "ms^(-2). Here, the ball experiences this acceleration for 1 second."
        typewriter(instruction, 20)
        wait_for_continue()

        screen.blit(zoomed_expl, [0, 0])
        screen.blit(v_arrow, [450, 50])

        velfont = pygame.font.Font('images/ARLRDBD.ttf', 27)
        velocity_text = velfont.render(str(vel) + 'm/s', True, (0, 0, 0))
        screen.blit(velocity_text, [450, 10])
        pygame.display.update()
        instruction = "Hence, the ball will reach a max velocity of " + \
            str(vel) + "m/s after 1s. The ball will only experience friction after that causing it to decelerate to a stop."
        typewriter(instruction, 20)
        wait_for_continue()

    def game_balls():
        global balls, ball
        balls = []
        for n in [0, 1, 2, 3]:
            filename = 'images/ball' + str(n) + '.png'
            ball = pygame.image.load(filename)
            ball = pygame.transform.scale(ball, (25, 25))
            balls.append(ball)

    def game_stick():
        global stick
        stick = pygame.transform.scale(stick, (150, 52))

    def push(F, t, f):
        global tries, acc, vel, stick_x, stick_y, ball_x, ball_y, rect_first_boundary, rect_second_boundary
        start_button.config(state="disabled")
        acc = acceleration(F, f)
        vel = velocity(acc, t)
        total_dist = displacement(vel, acc, t)

        ball_x_change = 0

        if tries > 2:
            ball_x = 142
            ball_y = 123
            stick_x = -10
            stick_y = 107
        if tries <= 2:
            ball_x = 340
            ball_y = 98
            stick_x = 30
            stick_y = 50

        ball_n = 0
        fps = 60

        vel_x = Force * 0.99

        clock = pygame.time.Clock()

        accelerating = False
        decelerating = False

        if tries == 1:
            explain()

        accelerating = True

        rect_first_boundary = 600
        rect_second_boundary = 650

        rotation = 0
        rotation_amt = 0

        start_button.config(state="disabled")

        while accelerating:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    accelerating = False

            if ball_x_change > vel_x:
                accelerating = False
                decelerating = True

            junglebackground()
            grassbackground()
            if tries >= 3:
                pygame.draw.rect(screen, (225, 0, 0),
                                 (rect_second_boundary, 148, 10, 40))
                pygame.draw.rect(screen, (225, 0, 0),
                                 (rect_first_boundary, 148, 10, 40))

            poolstick(stick_x, stick_y)
            ballimage(ball_n, ball_x, ball_y)

            if ball_x_change == 0:
                ball_x_change += 0.5

            ball_x_change = ball_x_change / 0.92
            ball_x += ball_x_change
            rotation += 0.025
            ball_n += rotation

            if ball_n > 3:
                ball_n = 0

            stick_x += ball_x_change

            clock.tick(fps)
            pygame.display.update()

        while decelerating:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    accelerating = False

            if ball_x_change <= 0.1:
                decelerating = False

            junglebackground()
            grassbackground()
            poolstick(stick_x, stick_y)
            ballimage(ball_n, ball_x, ball_y)
            if tries >= 3:
                pygame.draw.rect(screen, (225, 0, 0),
                                 (rect_first_boundary, 148, 10, 40))
                pygame.draw.rect(screen, (225, 0, 0),
                                 (rect_second_boundary, 148, 10, 40))

            ball_x_change *= 0.95
            ball_x += ball_x_change

            rotation *= 0.97
            ball_n += rotation
            if ball_n > 3:
                ball_n = 0

            clock.tick(fps)
            pygame.display.update()

            if ball_x > 800:
                decelerating = False

        tries += 1

        if tries == 2:
            instruction = "Try a different magnitude of Force!"
            typewriter(instruction, 20)
            start_button.config(state=NORMAL, bg='steel blue', fg='white')
        elif tries == 3:
            reset()
            pygame.draw.rect(screen, (225, 0, 0), (600, 148, 10, 40))
            pygame.draw.rect(screen, (225, 0, 0), (650, 148, 10, 40))
            pygame.display.update()
            force_scale.config(from_=17, to_=3)
            instruction = "You got the hang of it! Now try to stop the ball between the red lines."
            typewriter(instruction, 20)
            start_button.config(state=NORMAL, bg='steel blue', fg='white')

        else:
            checkwin()
            start_button.config(state=NORMAL, bg='steel blue', fg='white')

    def reset():
        ball_x = 142
        ball_y = 123
        stick_x = -10
        stick_y = 107
        junglebackground()
        grassbackground()
        game_balls()
        ballimage(0, 142, 123)
        game_stick()
        poolstick(-10, 107)

    def checkwin():

        if ball_x > rect_first_boundary and ball_x < rect_second_boundary:
            instruction = "   Well Played!!"
            typewriter(instruction, 20)
        else:
            instruction = "Failure is the pillar of success! Try again :)"
            typewriter(instruction, 20)

    def junglebackground():
        screen.blit(jungle, [-1100, -620])

    def grassbackground():
        screen.blit(grass, [0, -400])

    def poolstick(x, y):
        stickRect = pygame.Rect((x, y), (300, 107))
        screen.blit(stick, stickRect)

    def ballimage(number, x, y):
        new_ball = balls[int(number)]
        ballRect = pygame.Rect((x, y), (50, 50))
        screen.blit(new_ball, ballRect)

    def back():
        pygame.display.quit()
        typing_clip.stop()
        clip.stop()
        try:
            helproot
        except NameError:
            helproot_exists = False
        else:
            helproot_exists = True

        if helproot_exists:
            helproot.destroy()
        root2.destroy()
        main_window.deiconify()
        methods.type(main_window, menuclip, typing_clip, music_playing)

    def formula():
        tkMessageBox.showinfo('Formulas used:',
                              'F = m x a\nv = a *t\nv**2 = u**2 + 2as',
                              parent=root2)

    def helpme():
        global helproot
        try:
            helproot
        except NameError:
            helproot = methods.helpwindow(root2, 2)
        else:
            if helproot.winfo_exists() == 0:
                helproot = methods.helpwindow(root2, 2)
            else:
                helproot.deiconify()

    titletext = Label(root2,
                      text="NEWTON'S SECOND LAW OF MOTION",
                      fg='white',
                      width=33,
                      relief=SUNKEN,
                      font=("Comic Sans MS bold", 20),
                      bd=5,
                      bg='royalblue4')
    titletext.place(relx=0.475, rely=0.07, anchor=CENTER)
    deftext = Label(
        root2,
        text=
        "Theory: The second law states that acceleration of an object is dependent upon two variables - the net force acting upon the object and its mass.",
        relief=SUNKEN,
        fg='white',
        bg='royalblue4',
        font=("Comic Sans MS", 12),
        wraplength=900,
        bd=5)
    deftext.place(relx=0.5, rely=0.19, anchor=CENTER)

    # new frame for pygame
    pyg_width = 800
    half_pyg_width = pyg_width / 2
    pyg_height = 200
    half_pyg_height = pyg_height / 2
    embed = Frame(root2,
                  width=pyg_width,
                  height=pyg_height,
                  background="white",
                  highlightbackground="black",
                  highlightthickness=3)
    embed.place(relx=0.5, rely=0.28, anchor=N)
    root2.update()

    # insert pygame into tkinter frame
    os.environ['SDL_WINDOWID'] = str(embed.winfo_id())

    if sys.platform == "win32":
        os.environ['SDL_VIDEODRIVER'] = 'windib'

    pygame.display.init()

    screen = pygame.display.set_mode((pyg_width, pyg_height))
    jungle = pygame.image.load('images/jungle.png')
    jungle = pygame.transform.rotate(jungle, -5.0)
    grass = pygame.image.load('images/green-grass.png')
    grass = pygame.transform.scale(grass, (800, 800))
    stick = pygame.image.load('images/poolstick.png')
    stick = pygame.transform.scale(stick, (300, 107))
    stick = pygame.transform.rotate(stick, -7.5)
    zoomed_expl = pygame.image.load('images/zoomedball.jpeg')
    f_arrow = pygame.image.load('images/f_arrow.png')
    f_arrow = pygame.transform.scale(f_arrow, (120, 40))
    small_f_arrow = pygame.transform.scale(f_arrow, (60, 20))
    v_arrow = pygame.image.load('images/v_arrow.png')
    v_arrow = pygame.transform.scale(v_arrow, (63, 98))
    small_v_arrow = pygame.transform.scale(v_arrow, (21, 31))

    pygame.font.init()

    Forcefont = pygame.font.Font('images/ARLRDBD.ttf', 32)
    force = Forcefont.render('F = 10N', True, (0, 0, 0))
    forceRect = force.get_rect()
    frictionfont = pygame.font.Font('images/ARLRDBD.ttf', 22)
    friction_text = frictionfont.render('f = 2N', True, (0, 0, 0))
    frictionRect = friction_text.get_rect()

    # screen.blit(screenshot, [-100, -100])

    balls = []
    for n in [0, 1, 2, 3]:
        filename = 'images/' + 'ball' + str(n) + '.png'
        ball = pygame.image.load(filename)
        ball = pygame.transform.scale(ball, (50, 50))
        balls.append(ball)

    # insert jungle background
    junglebackground()

    # insert grass image
    grassbackground()

    # insert poolstick image
    poolstick(30, 50)
    # poolstick(-10, 100)

    # insert ball image
    ballimage(0, 340, 98)
    # ballimage(0, 142, 123)

    velfont = pygame.font.Font('images/ARLRDBD.ttf', 27)
    velocity_text = velfont.render('30m/s', True, (0, 0, 0))

    pygame.display.update()

    force_label = Label(root2,
                        text="Force (N):",
                        bg='royalblue4',
                        fg='white',
                        font=("Comic Sans MS", 13))
    force_label.place(relx=0.258, rely=0.73, anchor=CENTER)
    force_scale = Scale(root2,
                        from_=10,
                        to_=5,
                        width=50,
                        length=100,
                        repeatdelay=1000,
                        resolution=1,
                        sliderlength=50,
                        bg='royalblue4',
                        fg='white',
                        font=("Comic Sans MS", 12))
    force_scale.place(relx=0.25, rely=0.76, anchor=N)

    helpbut = Button(root2,
                     text="Help",
                     relief=RAISED,
                     font=("Comic Sans MS", 12),
                     fg='royalblue4',
                     bg="lightblue2",
                     bd=5,
                     command=helpme)
    helpbut.place(relx=0.84, rely=0.07, anchor=CENTER)

    back_btn = Button(root2,
                      text="Main Menu",
                      relief=RAISED,
                      font=("Comic Sans MS", 12),
                      fg='royalblue4',
                      bg="lightblue2",
                      bd=5,
                      command=back)
    back_btn.place(relx=0.94, rely=0.07, anchor=CENTER)

    message = Label(root2,
                    fg='white',
                    font=("Comic Sans MS", 12),
                    relief='ridge',
                    bd=5,
                    bg='steel blue',
                    text="",
                    anchor=W,
                    wraplength=700,
                    justify=LEFT,
                    width=79,
                    height=2)
    message.place(relx=0.5, rely=0.57, anchor=N)

    def typewriter(text, delay):
        typing_clip.play()

        def wait():
            var = IntVar()
            root2.after(delay, var.set, 1)
            root2.wait_variable(var)

        message_text = text
        message_display = ""

        for letter in message_text:
            message_display += letter
            wait()
            message.configure(text=message_display)
        typing_clip.stop()

    # background music
    # Def Music On:

    def musicon():
        clip.play()
        music_on.config(state=DISABLED, fg="grey")
        music_off.config(state=NORMAL, fg="royalblue4")

    # Def Music Off:

    def musicoff():
        clip.stop()
        music_on.config(state=NORMAL, fg="royalblue4")
        music_off.config(state=DISABLED, fg="grey")

    music_on = Button(root2,
                      text="ON",
                      command=musicon,
                      width=4,
                      font=("Comic Sans MS bold", 10),
                      relief=RAISED,
                      fg='royalblue4',
                      bg="lightblue2",
                      bd=3,
                      state="disabled")
    music_on.place(relx=0.045, rely=0.095, anchor=CENTER)

    music_off = Button(root2,
                       text="OFF",
                       command=musicoff,
                       width=5,
                       font=("Comic Sans MS bold", 10),
                       relief=RAISED,
                       fg='royalblue4',
                       bg="lightblue2",
                       bd=3)
    music_off.place(relx=0.105, rely=0.095, anchor=CENTER)

    music_label = Label(root2,
                        text="Music Status:",
                        font=("Comic Sans MS", 11),
                        fg="white",
                        bg="royalblue4",
                        bd=5,
                        height=1)
    music_label.place(relx=0.075, rely=0.04, anchor=CENTER)

    start_button = Button(root2,
                          text="Start",
                          command=lambda: push(force_scale.get(), 1, 2),
                          bd=5,
                          bg='steel blue',
                          fg='white',
                          font=("Comic Sans MS", 16),
                          width=10)

    start_button.place(relx=0.65, rely=0.85, anchor=CENTER)

    # Ask User whether wants to exit or not

    first_instruction = "Please choose the magnitude of Force you wish to apply on the ball and click Start"

    typewriter(first_instruction, 20)

    root2.mainloop()
Example #3
0
def creditfor(main_window, menuclip, typing_clip, music_playing):
    global clip, musicname
    root = Toplevel()
    root.grab_set()
    methods.centralise(root, 350, 350)
    root.resizable(0, 0)
    root.title("Credits")
    root.iconbitmap("images/newticon.ico")
    musicname = 'sounds/successsong.mp3'
    creditsclip = mp3play.load(musicname)
    creditsclip.play()
    background = ImageTk.PhotoImage(Image.open('images/darkgold.jpeg'))
    panel = Label(root, image=background)
    panel.pack(side='top', fill="both", expand="yes")
    panel.image = background

    def on_closing():
        creditsclip.stop()
        root.destroy()
        methods.type(main_window, menuclip, typing_clip, music_playing)

    root.protocol("WM_DELETE_WINDOW", on_closing)

    # Def Main Menu Button

    def back():
        creditsclip.stop()
        root.destroy()
        methods.type(main_window, menuclip, typing_clip, music_playing)

    titletext = Label(root,
                      text="Credits To",
                      font='castellar 18 bold',
                      relief=RIDGE,
                      bd=5,
                      bg='gold',
                      fg='black')
    titletext.place(relx=0.5, rely=0.07, anchor=CENTER)

    creditlabel = Label(root,
                        text="CA Team 3 \n\
----------------------\n\
(1) Mohamad Farhan Ahsan\n\
(2) Toh Zheng Aun \n\
(3) Andrew Ling Xian Hann \n\
(4) Theodore Lau Hui You \n\
\n\
@allrightsreserved \n\
@copyright2020",
                        font=("Comic Sans MS bold", 11),
                        fg="white",
                        bg="black",
                        bd=5,
                        height=11,
                        width=25,
                        justify=LEFT)
    creditlabel.place(relx=0.5, rely=0.5, anchor=CENTER)

    back_btn = Button(root,
                      text="Back",
                      relief=RAISED,
                      font=("Comic Sans MS", 12),
                      fg='white',
                      bg="black",
                      bd=5,
                      command=back,
                      height=1)
    back_btn.place(relx=0.5, rely=0.92, anchor=CENTER)
    return root
Example #4
0
def Newtons_Third_Law(main_window, menuclip, typing_clip, music_playing):
    root3 = Toplevel()
    methods.centralise(root3, 700, 700)
    root3.resizable(0, 0)
    root3.title("NEWTON'S THIRD LAW OF MOTION")
    root3.iconbitmap("images/newticon.ico")
    frame_title = Frame(root3)
    frame_title.pack(side=TOP, fill="both", expand=True)
    frame_title.configure(bg='royalblue4')
    frame_scale = Frame(root3)
    frame_scale.place(x=420, y=150)
    clip2 = mp3play.load('sounds/launch.mp3')

    global weight, mass, u, v, s, t, position, land2, sky, change
    mass = 0
    change = 0
    weight = 0
    thrust = 0
    acceleration1 = 0
    position = [0, 0, 0, 0]
    t = 0
    u = 0
    v = 1
    s = 1

    # Canvas
    animation = Canvas(root3,
                       width=300,
                       height=400,
                       relief='ridge',
                       bd=3,
                       bg='black')
    animation.place(x=20, y=100)

    force_diagram = Canvas(root3,
                           width=150,
                           height=150,
                           relief='ridge',
                           bd=3,
                           bg='lightblue')
    force_diagram.place(x=430, y=470)
    # Images

    # Typewriter label
    message = Label(root3,
                    fg='white',
                    font=("Comic Sans MS", 12),
                    relief='ridge',
                    bd=5,
                    bg='steel blue',
                    text="",
                    anchor=W,
                    wraplength=630,
                    justify=LEFT,
                    width=68,
                    height=2)
    message.place(relx=0.005, rely=0.905)

    # typewriter function

    def waitforcontinue():
        global new_button

        var = BooleanVar()
        new_button = Button(root3,
                            bd=5,
                            bg='royalblue4',
                            fg='white',
                            font=("Comic Sans MS", 12),
                            text="Next",
                            command=lambda: var.set(True))
        new_button.place(relx=0.9, rely=0.913)
        new_button.wait_variable(var)
        new_button.destroy()

    def typewriter(text, delay):
        typing_clip.play()

        def wait():
            var = IntVar()
            root3.after(delay, var.set, 1)
            root3.wait_variable(var)

        message_text = text
        message_display = ""

        for letter in message_text:
            message_display += letter
            wait()
            message.configure(text=message_display)
        typing_clip.stop()

    # Land
    land1 = ImageTk.PhotoImage(Image.open("images/land.jpeg"))
    land2 = animation.create_image(0, 430, anchor=SW, image=land1)

    # sky
    sky1_2 = ImageTk.PhotoImage(Image.open("images/sky.png"))
    sky = animation.create_image(0, -1400, anchor=NW, image=sky1_2)

    # rocket
    rocket1_2 = ImageTk.PhotoImage(Image.open("images/new_rocket1.png"))

    rocket2_2 = ImageTk.PhotoImage(Image.open("images/new_rocket2.png"))

    rocket3_2 = ImageTk.PhotoImage(Image.open("images/new_rocket3.png"))

    # fire
    fire2 = ImageTk.PhotoImage(Image.open("images/new_fire.png"))

    # people
    people = ImageTk.PhotoImage(Image.open("images/people.png"))
    people2 = animation.create_image(-420, 125, anchor=NW, image=people)

    # launchpad
    launchpad1 = ImageTk.PhotoImage(Image.open("images/launchpad.png"))
    launchpad2 = animation.create_image(-230, -15, anchor=NW, image=launchpad1)

    # force diagram
    points = [(75, 135), (55, 105), (65, 105), (65, 75), (85, 75), (85, 105),
              (95, 105)]
    points2 = [(75, 15), (55, 45), (65, 45), (65, 75), (85, 75), (85, 45),
               (95, 45)]

    force_diagram.create_polygon(points, outline="black", fill="red", width=2)
    force_diagram.create_polygon(points2,
                                 outline="black",
                                 fill="yellow",
                                 width=2)

    # Close
    def on_closing():
        if tkMessageBox.askokcancel("Quit",
                                    "Do you want to go back to Main Menu?"):
            back()
            clip2.stop()

    # Def Music On:
    def musicon():
        clip.play()
        music_on.config(state=DISABLED, fg="grey")
        music_off.config(state=NORMAL, fg="royalblue4")

    # Def Music Off:
    def musicoff():
        clip.stop()
        music_on.config(state=NORMAL, fg="royalblue4")
        music_off.config(state=DISABLED, fg="grey")

    global musicname, clip
    musicname = 'sounds/exciting.mp3'
    clip = mp3play.load(musicname)
    clip.play()
    root3.protocol("WM_DELETE_WINDOW", on_closing)

    # Def Help Button
    def helpme():
        global helproot
        try:
            helproot
        except NameError:
            helproot = methods.helpwindow(root3, 3)
        else:
            if helproot.winfo_exists() == 0:
                helproot = methods.helpwindow(root3, 3)
            else:
                helproot.deiconify()

    def reset_force():
        force_diagram.delete('all')
        points = [(75, 135), (55, 105), (65, 105), (65, 75), (85, 75),
                  (85, 105), (95, 105)]
        points2 = [(75, 15), (55, 45), (65, 45), (65, 75), (85, 75), (85, 45),
                   (95, 45)]
        force_diagram.create_polygon(points,
                                     outline="black",
                                     fill="red",
                                     width=2)
        force_diagram.create_polygon(points2,
                                     outline="black",
                                     fill="yellow",
                                     width=2)

    # reset
    def reset(rocket):
        global sky, land3, acceleration1, weight, position, people3, launchpad3, u, v, s, t, cover, cover_change, t
        t = 0
        t = 0
        u = 0
        v = 1
        s = 1
        position = [0, 0, 0, 0]
        weight = 0
        weight_label.set(('Weight:', weight, 'N'))
        acceleration1 = 0
        acceleration.set(("Acceleration:", acceleration1, "ms^(-2)"))
        thrust_1.set(("Thrust:", thrust, "N"))
        animation.delete('all')
        land3 = animation.create_image(0, 430, anchor=SW, image=land1)
        sky = animation.create_image(0, -1400, anchor=NW, image=sky1_2)
        rockets = animation.create_image(150, 160, image=rocket)
        people3 = animation.create_image(-420, 125, anchor=NW, image=people)
        launchpad3 = animation.create_image(-230,
                                            -15,
                                            anchor=NW,
                                            image=launchpad1)
        reset_force()

    # move

    def move():
        global position, distance, t, cover, cover_change
        cover *= cover_change
        animation.move(land3, 0, cover)
        animation.move(launchpad3, 0, cover)
        animation.move(people3, 0, cover)
        animation.move(sky, 0, cover)
        time.sleep(t)
        animation.after(1, repeat)

    def repeat():
        global u, v, s, t, weight, acceleration1, force1, factor, cover_change
        position = animation.coords(sky)
        if position[1] > -10:
            clip2.stop()
            if str(music_on['state']) == 'disabled':
                clip.play()
            else:
                clip.stop()
            Back.config(state=NORMAL, bg='light blue2', fg='royalblue4')
            weight = 0
            scale['state'] = 'active'
            scale.set(0)
            scale['state'] = 'disabled'
            eight_instruction = "Congratulations! Your rocket has made it into space! Choose a new rocket to run the test again or go back to Main Menu to try out another Law. "
            typewriter(eight_instruction, 15)
            rocket1.config(state=NORMAL, bg='steel blue', fg='white')
            rocket2.config(state=NORMAL, bg='steel blue', fg='white')
            rocket3.config(state=NORMAL, bg='steel blue', fg='white')

        else:
            t *= 0.99
            animation.after(1, move)

    # Thrust
    def up(value=None):
        global acceleration1, weight, t, force1, factor, mass, cover_change
        if weight > 0:
            Back['state'] = 'disabled'
            rocket1['state'] = 'disabled'
            rocket2['state'] = 'disabled'
            rocket3['state'] = 'disabled'
            fire3 = animation.create_image(fire_coords, 270, image=fire2)
            force1 = scale.get()
            force1 = round(force1, 2)
            force2 = float(weight)
            thrust_1.set(("Thrust:", str(force1), "N"))
            force1 = int(force1)
            force3 = force1 - force2
            acceleration1 = force3 / mass
            acceleration1 = round(acceleration1, 3)
            factor = (force1 - weight) * 0.0001
            forces()
            if force3 > 0:
                cover_change += factor
                acceleration.set(("Acceleration:", acceleration1, "ms^(-2)"))
                scale['state'] = 'disabled'
                clip.stop()
                clip2.play()
                repeat()

            else:
                return None

    # Rockets
    def rocket1mass():
        global weight, mass, rocket1_3, fire_coords, cover, cover_change, t
        fire_coords = 150
        mass = 10
        Label(root3,
              text=('Mass:', mass, 'kg'),
              bg='royalblue4',
              fg='white',
              font=("Comic Sans MS", 12)).place(relx=0.1,
                                                rely=0.76,
                                                anchor=CENTER)
        reset(rocket1_2)
        weight = 98.10
        weight_label.set(('Weight:', weight, 'N'))
        scale['state'] = 'active'
        t = 0.01
        cover_change = 1.009
        cover = 0.5

    def rocket2mass():
        global weight, mass, fire_coords, cover, cover_change, t
        mass = 20
        fire_coords = 140
        Label(root3,
              text=('Mass:', mass, 'kg'),
              bg='royalblue4',
              fg='white',
              font=("Comic Sans MS", 12)).place(relx=0.1,
                                                rely=0.76,
                                                anchor=CENTER)
        reset(rocket2_2)
        weight = 196.2
        weight_label.set(('Weight:', weight, 'N'))
        scale['state'] = 'active'
        t = 0.02
        cover_change = 1.0085
        cover = 0.4

    def rocket3mass():
        global weight, mass, fire_coords, cover, cover_change, t
        fire_coords = 146
        mass = 30
        Label(root3,
              text=('Mass:', mass, 'kg'),
              bg='royalblue4',
              fg='white',
              font=("Comic Sans MS", 12)).place(relx=0.1,
                                                rely=0.76,
                                                anchor=CENTER)
        reset(rocket3_2)
        weight = 294.3
        weight_label.set(('Weight:', weight, 'N'))
        scale['state'] = 'active'
        t = 0.03
        cover_change = 1.008
        cover = 0.3

    # Force Diagram
    def forces():
        global weight
        force_diagram.delete('all')
        points = [75, 135, 55, 105, 65, 105, 65, 75, 85, 75, 85, 105, 95, 105]
        force_diagram.create_polygon(points,
                                     outline="black",
                                     fill="red",
                                     width=2)
        change = scale.get()
        change = round(change, 2)
        x = 10 * (change / weight)
        if x > 10:
            x = 12
            points3 = [(75, 75 - 6 * x), (75 - 2 * x, 75 - 3 * x),
                       (75 - x, 75 - 3 * x), (75 - x, 75), (75 + x, 75),
                       (75 + x, 75 - 3 * x), (75 + 2 * x, 75 - 3 * x)]
            force_diagram.create_polygon(points3,
                                         outline="black",
                                         fill="green",
                                         width=2)
        else:
            points2 = [(75, 15 + 6 * x), (55 + 2 * x, 45 + 3 * x),
                       (65 + x, 45 + 3 * x), (65 + x, 75), (85 - x, 75),
                       (85 - x, 45 + 3 * x), (95 - 2 * x, 45 + 3 * x)]
            force_diagram.create_polygon(points2,
                                         outline="black",
                                         fill="yellow",
                                         width=2)
            points3 = [(75, 75 - 6 * x), (75 - 2 * x, 75 - 3 * x),
                       (75 - x, 75 - 3 * x), (75 - x, 75), (75 + x, 75),
                       (75 + x, 75 - 3 * x), (75 + 2 * x, 75 - 3 * x)]
            force_diagram.create_polygon(points3,
                                         outline="black",
                                         fill="green",
                                         width=2)

    # Questions
    def gravity():
        global helproot1
        try:
            helproot1
        except NameError:
            helproot1 = methods.helpwindow(root3, 6)
        else:
            if helproot1.winfo_exists() == 0:
                helproot1 = methods.helpwindow(root3, 6)
            else:
                helproot1.deiconify()
            try:
                helproot2
            except NameError:
                pass
            else:
                helproot2.destroy()

    def calc_acceleration():
        global helproot2
        try:
            helproot2
        except NameError:
            helproot2 = methods.helpwindow(root3, 7)
        else:
            if helproot2.winfo_exists() == 0:
                helproot2 = methods.helpwindow(root3, 7)
            else:
                helproot2.deiconify()
            try:
                helproot1
            except NameError:
                pass
            else:
                helproot1.destroy()

    # Widgets
    # Title
    title = Label(frame_title,
                  text="NEWTON'S THIRD LAW OF MOTION",
                  fg='white',
                  width=32,
                  relief=SUNKEN,
                  font=("Comic Sans MS bold", 16),
                  bd=5,
                  bg='royalblue4')
    title.place(relx=0.45, rely=0.05, anchor=CENTER)

    title = Label(
        frame_title,
        text=
        "Theory: For every action, there is an equal and opposite reaction",
        relief=SUNKEN,
        fg='white',
        bg='royalblue4',
        font=("Comic Sans MS", 12),
        wraplength=900,
        bd=5)
    title.place(relx=0.45, rely=0.115, anchor=CENTER)

    # Scale
    scale = Scale(frame_scale,
                  from_=500,
                  to_=0,
                  width=150,
                  length=300,
                  command=up,
                  repeatdelay=1090,
                  resolution=10,
                  bg='dodger blue3',
                  fg='yellow2',
                  font='castellar 12 bold',
                  activebackground='blue4',
                  troughcolor='royal blue3',
                  highlightbackground='cyan',
                  sliderlength=50,
                  state='disabled')
    scale.pack(expand=True)

    # Information
    Label(root3,
          text=('Mass:', mass, 'kg'),
          bg='royalblue4',
          fg='white',
          font=("Comic Sans MS", 12)).place(relx=0.1, rely=0.76, anchor=CENTER)

    weight_label = StringVar()
    weight_label.set(('Weight:', weight, 'N'))
    Label(root3,
          textvariable=(weight_label),
          bg='royalblue4',
          fg='white',
          font=("Comic Sans MS", 12)).place(relx=0.1,
                                            rely=0.815,
                                            anchor=CENTER)

    thrust_1 = StringVar()
    thrust_1.set(("Thrust:", thrust, "N"))
    thrust_2 = Label(root3,
                     textvariable=thrust_1,
                     bg='royalblue4',
                     fg='white',
                     font=("Comic Sans MS", 12))
    thrust_2.place(relx=0.4, rely=0.76, anchor=CENTER)

    acceleration = StringVar()
    acceleration.set(("Acceleration:", acceleration1, "ms^(-2)"))
    A = Label(root3,
              textvariable=acceleration,
              bg='royalblue4',
              fg='white',
              font=("Comic Sans MS", 12))
    A.place(relx=0.38, rely=0.815, anchor=CENTER)

    Label(root3, text="Weight", relief='ridge', bd=5, bg='red').place(x=590,
                                                                      y=580)
    Label(root3, text="Normal \nForce", relief='ridge', bd=5,
          bg='yellow').place(x=590, y=530)
    Label(root3, text="Upwards \nForce", relief='ridge', bd=5,
          bg='green').place(x=590, y=480)

    Label(root3,
          text="Thrust (N)",
          font='castellar 12 bold',
          relief='ridge',
          bd=5,
          bg='lightblue1').place(x=460, y=115)
    music_label = Label(frame_title,
                        text="Music Status:",
                        font=("Comic Sans MS", 11),
                        fg="white",
                        bg="royalblue4",
                        bd=5,
                        height=1)
    music_label.place(relx=0.070, rely=0.025, anchor=CENTER)

    # Buttons
    rocket1 = Button(root3,
                     text="Rocket 1",
                     command=rocket1mass,
                     bd=5,
                     bg='steel blue',
                     fg='grey',
                     font=("Comic Sans MS", 11),
                     state='disabled')
    rocket1.place(x=20, y=590)

    rocket2 = Button(root3,
                     text="Rocket 2",
                     command=rocket2mass,
                     bd=5,
                     bg='steel blue',
                     fg='grey',
                     font=("Comic Sans MS", 11),
                     state='disabled')
    rocket2.place(x=120, y=590)

    rocket3 = Button(root3,
                     text="Rocket 3",
                     command=rocket3mass,
                     bd=5,
                     bg='steel blue',
                     fg='grey',
                     font=("Comic Sans MS", 11),
                     state='disabled')
    rocket3.place(x=220, y=590)

    Explaination1 = Button(root3,
                           text="?",
                           font=("castellar 12 bold", 10),
                           bg='royalblue4',
                           fg='white',
                           command=gravity,
                           bd=3)
    Explaination1.place(relx=0.21, rely=0.815, anchor=CENTER)

    Explaination2 = Button(root3,
                           text="?",
                           font=("castellar 12 bold", 10),
                           bg='royalblue4',
                           fg='white',
                           command=calc_acceleration,
                           bd=3)
    Explaination2.place(relx=0.55, rely=0.815, anchor=CENTER)

    Help = Button(frame_title,
                  text="Help",
                  relief=RAISED,
                  font=("Comic Sans MS", 12),
                  fg='royalblue4',
                  bg="lightblue2",
                  bd=5,
                  command=helpme)
    Help.place(relx=0.8, rely=0.05, anchor=CENTER)

    music_on = Button(frame_title,
                      text="ON",
                      command=musicon,
                      width=4,
                      font=("Comic Sans MS bold", 8),
                      relief=RAISED,
                      fg='royalblue4',
                      bg="lightblue2",
                      bd=3,
                      state="disabled")
    music_on.place(relx=0.032, rely=0.07, anchor=CENTER)

    music_off = Button(frame_title,
                       text="OFF",
                       command=musicoff,
                       width=5,
                       font=("Comic Sans MS bold", 8),
                       relief=RAISED,
                       fg='royalblue4',
                       bg="lightblue2",
                       bd=3)
    music_off.place(relx=0.098, rely=0.07, anchor=CENTER)

    def check_helproots(helproot):
        try:
            helproot
        except NameError:
            helproot_exists = False
        else:
            helproot_exists = True

    def back():
        typing_clip.stop()
        clip.stop()
        try:
            helproot
        except NameError:
            helproot_exists = False
        else:
            helproot_exists = True

        try:
            helproot1
        except NameError:
            helproot1_exists = False
        else:
            helproot1_exists = True

        try:
            helproot2
        except NameError:
            helproot2_exists = False
        else:
            helproot2_exists = True

        if helproot_exists:
            helproot.destroy()
        if helproot1_exists:
            helproot1.destroy()
        if helproot2_exists:
            helproot2.destroy()

        root3.destroy()
        main_window.deiconify()
        methods.type(main_window, menuclip, typing_clip, music_playing)

    Back = Button(frame_title,
                  text="Main Menu",
                  relief=RAISED,
                  font=("Comic Sans MS", 12),
                  fg='royalblue4',
                  bg="lightblue2",
                  bd=5,
                  command=back)
    Back.place(relx=0.92, rely=0.05, anchor=CENTER)

    # Messages
    first_instruction = "Newton's Third Law of Motion states that for every action, there will be an equal opposite reaction."
    typewriter(first_instruction, 30)
    waitforcontinue()

    second_instruction = "A stationary rocket has its weight equal to the normal reaction force."
    typewriter(second_instruction, 30)
    waitforcontinue()

    third_instruction = "When the rocket's boosters are ignited, thrust pushes fuel downwards. The fuel produces an equal and opposite force pushing the rocket upwards."
    typewriter(third_instruction, 30)
    waitforcontinue()

    fourth_instruction = "This balance of Forces is illustrated in the Force Diagram on the right."
    typewriter(fourth_instruction, 30)
    waitforcontinue()

    fifth_instruction = "Click the help button for further assistance. All the best on exploring!!"
    typewriter(fifth_instruction, 30)
    waitforcontinue()

    rocket1.config(state=NORMAL, bg='steel blue', fg='white')
    rocket2.config(state=NORMAL, bg='steel blue', fg='white')
    rocket3.config(state=NORMAL, bg='steel blue', fg='white')

    root3.mainloop()
Example #5
0
def quiz(main_window, menuclip, typing_clip, music_playing):
    root = Toplevel()
    root.title("NEWTON'S LAWS OF MOTION - MINI QUIZ")
    methods.centralise(root, 625, 350)
    root.iconbitmap("images/newticon.ico")
    root.resizable(0, 0)
    musicname = 'sounds/calm.mp3'
    clip = mp3play.load(musicname)
    clip.play()

    global windows, windows3, windows4, windows5, windows6, windows7, count
    count = 0
    windows = Toplevel(root)
    windows.withdraw()
    windows.iconbitmap("images/newticon.ico")
    windows.title("Question 1")
    windows.geometry("610x400+400+200")
    windows.resizable(0, 0)

    windows3 = Toplevel(root)
    windows3.withdraw()
    windows3.iconbitmap("images/newticon.ico")
    windows3.title("Question 2")
    windows3.geometry("610x400+400+200")
    windows3.resizable(0, 0)

    windows4 = Toplevel(root)
    windows4.withdraw()
    windows4.iconbitmap("images/newticon.ico")
    windows4.title("Question 3")
    windows4.geometry("610x400+400+200")
    windows4.resizable(0, 0)

    windows5 = Toplevel(root)
    windows5.withdraw()
    windows5.iconbitmap("images/newticon.ico")
    windows5.title("Question 4")
    windows5.geometry("610x400+400+200")
    windows5.resizable(0, 0)

    windows6 = Toplevel(root)
    windows6.withdraw()
    windows6.iconbitmap("images/newticon.ico")
    windows6.title("Question 5")
    windows6.geometry("610x400+400+200")
    windows6.resizable(0, 0)

    windows7 = Toplevel(windows5)
    windows7.withdraw()
    windows7.iconbitmap("images/newticon.ico")
    windows7.title("Final Result")
    windows7.geometry("600x400+400+200")
    windows7.resizable(0, 0)

    # Background
    global total

    background = ImageTk.PhotoImage(Image.open('images/quizbg.jpeg'))
    panel = Label(root, image=background)
    panel.pack(fill="both", expand="yes")

    backgroundx1 = ImageTk.PhotoImage(Image.open('images/ques1.jpeg'))
    panel1 = Label(windows, image=backgroundx1)
    panel1.pack(fill="both", expand="yes")

    backgroundx2 = ImageTk.PhotoImage(Image.open('images/ques2.jpeg'))
    panel2 = Label(windows3, image=backgroundx2)
    panel2.pack(fill="both", expand="yes")

    backgroundx3 = ImageTk.PhotoImage(Image.open('images/ques3.jpeg'))
    panel3 = Label(windows4, image=backgroundx3)
    panel3.pack(fill="both", expand="yes")

    backgroundx4 = ImageTk.PhotoImage(Image.open('images/ques4.jpeg'))
    panel4 = Label(windows5, image=backgroundx4)
    panel4.pack(fill="both", expand="yes")

    backgroundx5 = ImageTk.PhotoImage(Image.open('images/ques5.jpeg'))
    panel5 = Label(windows6, image=backgroundx5)
    panel5.pack(fill="both", expand="yes")

    resultbackground = ImageTk.PhotoImage(
        Image.open('images/projectornew.jpeg'))

    # questions
    q = [
        "Acceleration of an object is dependent upon two variables \n- the net force acting \
upon the object and its mass.\nWhich law is this statement referring to?",
        "Referring to the formula 'F=ma',where F = force,\n m = mass and a = acceleration. \n\
What happens if the acceleration increases,\n provided that the mass is a constant?",
        "For every action, there is an ______ and ______ reaction. \nFill in the blanks.",
        "Which of the following is equivalent to the equation F=ma?",
        "A snooker of mass 150g ball was initially stationary.\n\
Referring to the formula F=ma, find the net force \n\
needed to move the ball at a speed of \n\
6 meter per second in a time of 0.05 seconds."
    ]

    a0 = [
        "Newton's First Law of Motion", "Newton's Second Law of Motion",
        "Newton's Third Law of Motion"
    ]
    a1 = [
        "The force increases", "The force decreases",
        "There is no change in force."
    ]
    a2 = ["equal, parallel", "unequal, opposite", "equal, opposite"]
    a3 = [" F = (mv-mu)/2t", " F = m(v-u)/t ", "F = (mv)/t(mu)"]
    a4 = ["18 N", "1.8 N", "-18 N"]

    def bnext():
        global cb1, cb2, cb3, windows, btn1, btn2, count
        root.withdraw()
        windows.deiconify()
        if count == 0:
            lbll = Label(windows,
                         text=q[0],
                         font=("Comic Sans MS bold", 11),
                         bg="black",
                         fg='white')
            lbll.place(relx=0.55, rely=0.35, anchor=CENTER)
            count += 1

        cb1 = Radiobutton(windows,
                          text=a0[0],
                          value=0,
                          variable=v0,
                          activeforeground='blue',
                          cursor='hand2',
                          font=("Comic Sans MS bold", 11))
        cb1.place(relx=0.5, rely=0.5, anchor=CENTER)
        cb2 = Radiobutton(windows,
                          text=a0[1],
                          value=1,
                          variable=v0,
                          activeforeground='blue',
                          cursor='hand2',
                          font=("Comic Sans MS bold", 11))
        cb2.place(relx=0.515, rely=0.6, anchor=CENTER)
        cb3 = Radiobutton(windows,
                          text=a0[2],
                          value=2,
                          variable=v0,
                          activeforeground='blue',
                          cursor='hand2',
                          font=("Comic Sans MS bold", 11))
        cb3.place(relx=0.505, rely=0.7, anchor=CENTER)
        btn1 = Button(windows,
                      text="next",
                      font=('arial', 12, 'bold'),
                      cursor='gumby',
                      fg='black',
                      bg='white',
                      command=bnext2,
                      relief=RAISED,
                      bd=5)
        btn1.place(relx=0.85, rely=0.85, anchor=CENTER)
        btn2 = Button(windows,
                      text="back",
                      font=('arial', 12, 'bold'),
                      cursor='gumby',
                      fg='black',
                      bg='white',
                      command=bback,
                      relief=RAISED,
                      bd=5)
        btn2.place(relx=0.15, rely=0.85, anchor=CENTER)
        windows.protocol("WM_DELETE_WINDOW", on_closing)

    def bnext2():
        global cb4, cb5, cb6, windows3, btn3, count
        windows.withdraw()
        windows3.deiconify()
        if count == 1:
            lbl2 = Label(windows3,
                         text=q[1],
                         font=("Comic Sans MS bold", 11),
                         bg="black",
                         fg='white')
            lbl2.place(relx=0.55, rely=0.32, anchor=CENTER)
            count += 1

        cb4 = Radiobutton(windows3,
                          text=a1[0],
                          value=0,
                          variable=v1,
                          activeforeground='blue',
                          cursor='hand2',
                          font=("Comic Sans MS bold", 11))
        cb4.place(relx=0.5, rely=0.5, anchor=CENTER)
        cb5 = Radiobutton(windows3,
                          text=a1[1],
                          value=1,
                          variable=v1,
                          activeforeground='blue',
                          cursor='hand2',
                          font=("Comic Sans MS bold", 11))
        cb5.place(relx=0.505, rely=0.6, anchor=CENTER)
        cb6 = Radiobutton(windows3,
                          text=a1[2],
                          value=2,
                          variable=v1,
                          activeforeground='blue',
                          cursor='hand2',
                          font=("Comic Sans MS bold", 11))
        cb6.place(relx=0.5525, rely=0.7, anchor=CENTER)
        btn3 = Button(windows3,
                      text="next",
                      font=('arial', 12, 'bold'),
                      cursor='gumby',
                      fg='black',
                      bg='white',
                      command=bnext3,
                      relief=RAISED,
                      bd=5)
        btn3.place(relx=0.85, rely=0.85, anchor=CENTER)
        btn4 = Button(windows3,
                      text="back",
                      font=('arial', 12, 'bold'),
                      cursor='gumby',
                      fg='black',
                      bg='white',
                      command=bback2,
                      relief=RAISED,
                      bd=5)
        btn4.place(relx=0.15, rely=0.85, anchor=CENTER)
        windows3.protocol("WM_DELETE_WINDOW", on_closing)

    def bnext3():
        global cb7, cb8, cb9, windows4, btn5, count
        windows3.withdraw()
        windows4.deiconify()
        if count == 2:
            lbl2 = Label(windows4,
                         text=q[2],
                         font=("Comic Sans MS bold", 11),
                         bg="black",
                         fg='white')
            lbl2.place(relx=0.55, rely=0.33, anchor=CENTER)
            count += 1

        cb7 = Radiobutton(windows4,
                          text=a2[0],
                          value=0,
                          variable=v2,
                          activeforeground='blue',
                          cursor='hand2',
                          font=("Comic Sans MS bold", 11))
        cb7.place(relx=0.49, rely=0.5, anchor=CENTER)
        cb8 = Radiobutton(windows4,
                          text=a2[1],
                          value=1,
                          variable=v2,
                          activeforeground='blue',
                          cursor='hand2',
                          font=("Comic Sans MS bold", 11))
        cb8.place(relx=0.51, rely=0.6, anchor=CENTER)
        cb9 = Radiobutton(windows4,
                          text=a2[2],
                          value=2,
                          variable=v2,
                          activeforeground='blue',
                          cursor='hand2',
                          font=("Comic Sans MS bold", 11))
        cb9.place(relx=0.495, rely=0.7, anchor=CENTER)
        btn5 = Button(windows4,
                      text="next",
                      font=('arial', 12, 'bold'),
                      cursor='gumby',
                      fg='black',
                      bg='white',
                      command=bnext4,
                      relief=RAISED,
                      bd=5)
        btn5.place(relx=0.85, rely=0.85, anchor=CENTER)
        btn6 = Button(windows4,
                      text="back",
                      font=('arial', 12, 'bold'),
                      cursor='gumby',
                      fg='black',
                      bg='white',
                      command=bback3,
                      relief=RAISED,
                      bd=5)
        btn6.place(relx=0.15, rely=0.85, anchor=CENTER)
        windows4.protocol("WM_DELETE_WINDOW", on_closing)

    def bnext4():
        global cb10, cb11, cb12, windows5, btn7, count
        windows4.withdraw()
        windows5.deiconify()
        if count == 3:
            lbl2 = Label(windows5,
                         text=q[3],
                         font=("Comic Sans MS bold", 11),
                         bg="black",
                         fg='white')
            lbl2.place(relx=0.55, rely=0.32, anchor=CENTER)
            count += 1

        cb10 = Radiobutton(windows5,
                           text=a3[0],
                           value=0,
                           variable=v3,
                           activeforeground='blue',
                           cursor='hand2',
                           font=("Comic Sans MS bold", 11))
        cb10.place(relx=0.48, rely=0.5, anchor=CENTER)
        cb11 = Radiobutton(windows5,
                           text=a3[1],
                           value=1,
                           variable=v3,
                           activeforeground='blue',
                           cursor='hand2',
                           font=("Comic Sans MS bold", 11))
        cb11.place(relx=0.47, rely=0.6, anchor=CENTER)
        cb12 = Radiobutton(windows5,
                           text=a3[2],
                           value=2,
                           variable=v3,
                           activeforeground='blue',
                           cursor='hand2',
                           font=("Comic Sans MS bold", 11))
        cb12.place(relx=0.47, rely=0.7, anchor=CENTER)
        btn7 = Button(windows5,
                      text="next",
                      font=('arial', 12, 'bold'),
                      cursor='gumby',
                      fg='black',
                      bg='white',
                      command=bnext5,
                      relief=RAISED,
                      bd=5)
        btn7.place(relx=0.85, rely=0.85, anchor=CENTER)
        btn8 = Button(windows5,
                      text="back",
                      font=('arial', 12, 'bold'),
                      cursor='gumby',
                      fg='black',
                      bg='white',
                      command=bback4,
                      relief=RAISED,
                      bd=5)
        btn8.place(relx=0.15, rely=0.85, anchor=CENTER)
        windows5.protocol("WM_DELETE_WINDOW", on_closing)

    def bnext5():
        global cb13, cb14, cb15, windows6, btn9, count
        windows5.withdraw()
        windows6.deiconify()
        if count == 4:
            lbl2 = Label(windows6,
                         text=q[4],
                         font=("Comic Sans MS bold", 11),
                         bg="black",
                         fg='white')
            lbl2.place(relx=0.55, rely=0.3, anchor=CENTER)
            count += 1

        cb13 = Radiobutton(windows6,
                           text=a4[0],
                           value=0,
                           variable=v4,
                           activeforeground='blue',
                           cursor='hand2',
                           font=("Comic Sans MS bold", 11))
        cb13.place(relx=0.495, rely=0.5, anchor=CENTER)
        cb14 = Radiobutton(windows6,
                           text=a4[1],
                           value=1,
                           variable=v4,
                           activeforeground='blue',
                           cursor='hand2',
                           font=("Comic Sans MS bold", 11))
        cb14.place(relx=0.5, rely=0.6, anchor=CENTER)
        cb15 = Radiobutton(windows6,
                           text=a4[2],
                           value=2,
                           variable=v4,
                           activeforeground='blue',
                           cursor='hand2',
                           font=("Comic Sans MS bold", 11))
        cb15.place(relx=0.5, rely=0.7, anchor=CENTER)
        btn9 = Button(windows6,
                      text="Results",
                      font=('arial', 12, 'bold'),
                      cursor='gumby',
                      fg='black',
                      bg='white',
                      command=results,
                      relief=RAISED,
                      bd=5)
        btn9.place(relx=0.85, rely=0.85, anchor=CENTER)
        btn10 = Button(windows6,
                       text="back",
                       font=('arial', 12, 'bold'),
                       cursor='gumby',
                       fg='black',
                       bg='white',
                       command=bback5,
                       relief=RAISED,
                       bd=5)
        btn10.place(relx=0.15, rely=0.85, anchor=CENTER)
        windows6.protocol("WM_DELETE_WINDOW", on_closing)

    # back button
    def bback():
        windows.withdraw()
        root.deiconify()

    def bback2():
        windows.deiconify()
        windows3.withdraw()

    def bback3():
        windows3.deiconify()
        windows4.withdraw()

    def bback4():
        windows4.deiconify()
        windows5.withdraw()

    def bback5():
        windows5.deiconify()
        windows6.withdraw()

    # next_button
    def next1():
        windows3.deiconify()
        windows.withdraw()

    def next2():
        windows4.deiconify()
        windows3.withdraw()

    def next3():
        windows5.deiconify()
        windows4.withdraw()

    def next4():
        windows6.deiconify()
        windows5.withdraw()

    def next5():
        windows7.deiconify()
        windows6.withdraw()

    class correction():
        def __init__(self, first, second, third, button, nexts):
            first['state'] = 'disabled'
            second['state'] = 'disabled'
            third['state'] = 'disabled'
            button.configure(command=nexts)

    # Tells the correct answer
    def checked():
        global total
        total = 0

        if v0.get() == 1:
            total += 1
            cb2.configure(bg='green')
        else:
            cb2.configure(bg='red')
        if v1.get() == 0:
            total += 1
            cb4.configure(bg='green')
        else:
            cb4.configure(bg='red')

        if v2.get() == 2:
            total += 1
            cb9.configure(bg='green')
        else:
            cb9.configure(bg='red')

        if v3.get() == 1:
            total += 1
            cb11.configure(bg='green')
        else:
            cb11.configure(bg='red')

        if v4.get() == 0:
            total += 1
            cb13.configure(bg='green')
        else:
            cb13.configure(bg='red')

    # Def backmm (back to main menu)
    def backmm():
        clip.stop()
        try:
            helproot
        except NameError:
            helproot_exists = False
        else:
            helproot_exists = True

        if helproot_exists:
            helproot.destroy()
        root.destroy()
        main_window.deiconify()
        methods.type(main_window, menuclip, typing_clip, music_playing)

    # Def Help Button
    def helpme():
        global helproot
        try:
            helproot
        except NameError:
            helproot = methods.helpwindow(root, 5)
        else:
            if helproot.winfo_exists() == 0:
                helproot = methods.helpwindow(root, 5)
            else:
                helproot.deiconify()

    # Marking Scheme
    def results():
        global windows7
        checked()
        windows6.withdraw()
        windows7.deiconify()
        if total == 5:
            panel1 = Label(windows7, image=resultbackground)
            panel1.pack()  # panel1.place(relx=0,rely=0)
            bf = Label(windows7,
                       text="Score: " + str(total) + "/5",
                       font=("Comic Sans MS bold", 20),
                       fg="blue",
                       bg='white')
            bf.place(relx=0.5, rely=0.35, anchor=CENTER)
            bf1 = Label(
                windows7,
                text=
                "Good Job!\n You have a strong understanding \n of Newton's Law of Motions.",
                font=("Comic Sans MS bold", 11),
                fg='black',
                bg='white',
                wraplength=300)
            bf1.place(relx=0.5, rely=0.55, anchor=CENTER)
        if total == 4 or total == 3:
            panel2 = Label(windows7, image=resultbackground)
            panel2.pack()  # panel2.place(relx=0,rely=0)
            bf = Label(windows7,
                       text="Score: " + str(total) + "/5",
                       font=("Comic Sans MS bold", 20),
                       fg="purple",
                       bg='white')
            bf.place(relx=0.5, rely=0.35, anchor=CENTER)
            bf1 = Label(
                windows7,
                text=
                "Nice Try!\n You have basic understanding \n of the topic but you need \n to work harder.",
                font=("Comic Sans MS bold", 11),
                fg='black',
                bg='white',
                wraplength=300)
            bf1.place(relx=0.5, rely=0.55, anchor=CENTER)
        if total < 3:
            panel3 = Label(windows7, image=resultbackground)
            panel3.pack()  # panel3.place(relx=0,rely=0)
            bf = Label(windows7,
                       text="Score: " + str(total) + "/5",
                       font=("Comic Sans MS bold", 20),
                       fg="red",
                       bg='white')
            bf.place(relx=0.5, rely=0.35, anchor=CENTER)
            bf1 = Label(
                windows7,
                text=
                "Fail!\n You have not understood \n Newton's Law of Motions. \n Go through the programmes again.",
                font=("Comic Sans MS bold", 11),
                fg='black',
                bg='white',
                wraplength=300)
            bf1.place(relx=0.5, rely=0.55, anchor=CENTER)
        btn100 = Button(windows7,
                        cursor='gumby',
                        text="Answers",
                        font=("Comic Sans MS", 12),
                        fg='black',
                        bg='white',
                        command=answers,
                        relief=RAISED,
                        bd=5)
        btn100.place(relx=0.85, rely=0.94, anchor=CENTER)
        bquit = Button(windows7,
                       text="Main Menu",
                       font=("Comic Sans MS", 12),
                       fg='black',
                       bg='white',
                       cursor='gumby',
                       command=backmm,
                       relief=RAISED,
                       bd=5)
        bquit.place(relx=0.15, rely=0.94, anchor=CENTER)
        windows7.protocol("WM_DELETE_WINDOW", on_closing)
        windows6.mainloop()

    # Showing Correct Answers
    def answers():
        btn2['state'] = 'disabled'
        windows7.withdraw()
        windows.deiconify()
        correction(cb1, cb2, cb3, btn1, next1)
        correction(cb4, cb5, cb6, btn3, next2)
        correction(cb7, cb8, cb9, btn5, next3)
        correction(cb10, cb11, cb12, btn7, next4)
        correction(cb13, cb14, cb15, btn9, next5)
        windows.mainloop()

    # Labels
    lbl0 = Label(root,
                 text="MINI QUIZ",
                 font=("Comic Sans MS", 22),
                 fg='white',
                 bg='black',
                 relief=SUNKEN,
                 bd=5)
    lbl0.place(relx=0.5, rely=0.31, anchor=CENTER)
    lbl00 = Label(root,
                  text="#all about Newton's Laws of Motion!",
                  font=("Comic Sans MS", 12),
                  fg='white',
                  bg='black',
                  relief=SUNKEN,
                  bd=4)
    lbl00.place(relx=0.5, rely=0.44, anchor=CENTER)

    # Buttons
    beginbtn = Button(root,
                      text="BEGIN",
                      font=("Comic Sans MS", 12),
                      cursor='gumby',
                      fg='white',
                      bg='crimson',
                      relief=RAISED,
                      bd=5,
                      command=bnext)
    beginbtn.place(relx=0.5, rely=0.6, anchor=CENTER)

    mainmenubtn = Button(root,
                         text="Main Menu",
                         font=("Comic Sans MS", 12),
                         cursor='gumby',
                         fg='white',
                         bg='black',
                         relief=RAISED,
                         bd=5,
                         command=backmm)
    mainmenubtn.place(relx=0.87, rely=0.12, anchor=CENTER)

    helpbut = Button(root,
                     text="Help",
                     font=("Comic Sans MS", 12),
                     cursor='gumby',
                     fg='white',
                     bg='black',
                     relief=RAISED,
                     bd=5,
                     command=helpme)
    helpbut.place(relx=0.72, rely=0.12, anchor=CENTER)

    # Def Music On:
    def musicon():
        clip.play()
        music_on.config(state=DISABLED, fg="grey")
        music_off.config(state=NORMAL, fg="white")

    # Def Music Off:
    def musicoff():
        clip.stop()
        music_on.config(state=NORMAL, fg="white")
        music_off.config(state=DISABLED, fg="grey")

    # Music
    music_on = Button(root,
                      text="ON",
                      command=musicon,
                      font=("Comic Sans MS", 10),
                      fg='white',
                      bg='black',
                      relief=RAISED,
                      bd=3,
                      state="disabled",
                      width=6)
    music_on.place(relx=0.065, rely=0.21, anchor=CENTER)

    music_off = Button(root,
                       text="OFF",
                       command=musicoff,
                       font=("Comic Sans MS", 10),
                       fg='white',
                       bg='black',
                       relief=RAISED,
                       bd=3,
                       width=7)
    music_off.place(relx=0.17, rely=0.21, anchor=CENTER)

    music_label = Label(root,
                        text="Music Status:",
                        font=("Comic Sans MS", 12),
                        relief=SUNKEN,
                        bd=3,
                        fg='white',
                        bg="black",
                        width=12)
    music_label.place(relx=0.12, rely=0.11, anchor=CENTER)

    # Ask User whether wants to exit or not
    def on_closing():
        if tkMessageBox.askokcancel("Quit",
                                    "Do you want to go back to Main Menu?"):
            backmm()

    v0 = IntVar()
    v1 = IntVar()
    v2 = IntVar()
    v3 = IntVar()
    v4 = IntVar()

    root.protocol("WM_DELETE_WINDOW", on_closing)
    root.mainloop()
Example #6
0
def window():
    global main_window, music_on

    main_window = Tk()
    methods.centralise(main_window, 1000, 580)
    main_window.title("Newton's Laws of Motion")
    main_window.iconbitmap("images/newticon.ico")
    main_window.wm_attributes("-topmost", False)

    main_window.resizable(0, 0)
    background = ImageTk.PhotoImage(Image.open('images/bluepixels.png'))
    panel = Label(main_window, image=background)
    panel.pack(side='top', fill="both", expand="yes")
    panel.image = background

    main_window.protocol("WM_DELETE_WINDOW", close_window)

    newtlabelx = Label(main_window,
                       text="WELCOME TO NEWT",
                       font=("Comic Sans MS", 37),
                       fg='white',
                       bg='royalblue4',
                       relief=SUNKEN,
                       bd=5,
                       width=18,
                       height=1)
    newtlabelx.place(relx=0.1, rely=0.2)

    newton1_button = Button(main_window,
                            text="Newton's First Law",
                            bd=3,
                            bg='royalblue1',
                            width=30,
                            height=1,
                            font=("Comic Sans MS", 12),
                            fg='white',
                            command=first_law)
    newton1_button.place(relx=0.1, rely=0.45)

    newton2_button = Button(main_window,
                            text="Newton's Second Law",
                            bd=3,
                            bg='royalblue2',
                            width=30,
                            height=1,
                            font=("Comic Sans MS", 12),
                            fg='white',
                            command=second_law)
    newton2_button.place(relx=0.1, rely=0.522)

    newton3_button = Button(main_window,
                            text="Newton's Third Law",
                            bd=3,
                            bg='royalblue3',
                            width=30,
                            height=1,
                            font=("Comic Sans MS", 12),
                            fg='white',
                            command=third_law)
    newton3_button.place(relx=0.1, rely=0.594)

    quiz_button = Button(main_window,
                         text="Mini Quiz",
                         bd=3,
                         bg='royalblue4',
                         width=30,
                         height=1,
                         font=("Comic Sans MS", 12),
                         fg='white',
                         command=quizz)
    quiz_button.place(relx=0.1, rely=0.667)

    exit_button = Button(main_window,
                         text="Exit",
                         bd=4,
                         bg='lightblue2',
                         width=6,
                         height=1,
                         font=("Comic Sans MS", 12),
                         fg='royalblue4',
                         command=close_window)
    exit_button.place(relx=0.9, rely=0.05)

    help_button = Button(main_window,
                         text="Help",
                         bd=4,
                         bg='lightblue2',
                         width=4,
                         height=1,
                         font=("Comic Sans MS", 12),
                         fg='royalblue4',
                         command=helpme)
    help_button.place(relx=0.84, rely=0.05)

    credits_button = Button(main_window,
                            text="Credits",
                            bd=4,
                            bg='lightblue2',
                            width=6,
                            height=1,
                            font=("Comic Sans MS", 12),
                            fg='royalblue4',
                            command=creditsto)
    credits_button.place(relx=0.76, rely=0.05)

    # Def Music On:

    def musicon():
        clip.play()
        music_on.config(state=DISABLED, fg="grey")
        music_off.config(state=NORMAL, fg="white")

    # Def Music Off:

    def musicoff():
        clip.stop()
        music_on.config(state=NORMAL, fg="white")
        music_off.config(state=DISABLED, fg="grey")

    # Music
    music_label = Label(main_window,
                        text="Music Status:",
                        font=("Comic Sans MS", 14),
                        fg='royalblue4',
                        bg='lightblue2',
                        height=1)
    music_label.place(relx=0.082, rely=0.051, anchor=CENTER)

    music_on = Button(main_window,
                      text="ON",
                      relief=RAISED,
                      fg='white',
                      command=musicon,
                      font=("Comic Sans MS bold", 10),
                      width=6,
                      bg='royalblue4',
                      bd=3,
                      state=DISABLED)
    music_on.place(relx=0.051, rely=0.1183, anchor=CENTER)

    music_off = Button(main_window,
                       text="OFF",
                       relief=RAISED,
                       fg='white',
                       command=musicoff,
                       font=("Comic Sans MS bold", 10),
                       width=6,
                       bg='royalblue4',
                       bd=3,
                       state=NORMAL)
    music_off.place(relx=0.112, rely=0.1183, anchor=CENTER)
    music_playing = True
    # Typewriter
    newtlabeltw = Label(main_window,
                        text="Do You Know?",
                        relief='ridge',
                        bd=5,
                        font=("Comic Sans MS", 16),
                        fg='white',
                        bg='royalblue4')
    newtlabeltw.place(relx=0.1, rely=0.8)

    methods.type(main_window, clip, typing_clip, music_playing)