Beispiel #1
0
def make_menu(tk: Tk):
    """
    It's a selection activity constructor. It creates required widgets. WHat's more, it binds
    option buttons to transitions to other scenes and to the host OS.
    """
    frame = Frame(tk,
                  highlightthickness=2,
                  bg=BACKGROUND_COLOR,
                  highlightbackground=ACCENT_COLOR,
                  padx=5,
                  pady=10)
    frame.place_configure(relx=0.5, rely=0.5, anchor='center')
    options = [('Play', go_to_scene(make_game, tk, frame)),
               ('Help', go_to_scene(make_help, tk, frame)),
               ('Quit', quit_tk(tk))]
    for text, command in options:
        button = Button(frame,
                        relief='flat',
                        highlightthickness=0,
                        bg=ACCENT_COLOR,
                        fg=BUTTON_TEXT_COLOR,
                        activebackground=HOVER_COLOR,
                        activeforeground=BUTTON_TEXT_COLOR,
                        text=text,
                        font=BUTTON_FONT,
                        command=command)
        button.pack_configure(padx=25, pady=18, ipadx=70, ipady=8, fill='x')
Beispiel #2
0
def make_help(tk: Tk):
    """
    Renders a helping message with a brief description of the game rules.
    """
    frame = Frame(tk, bg=BACKGROUND_COLOR, padx=10, pady=30)
    frame.place_configure(relx=0.5, rely=0.5, anchor='center')
    contents = [
        ('ping-pong', HEADER_FONT),
        ('It\'s a classic ping-pong game, where you\'re to hit the ball\n'
         'using the paddle. The more ball doesn\'t hit the floor, the\n'
         'more points you score. Use left and right arrows to move\n'
         'the paddle.', PARAGRAPH_FONT)
    ]
    for text, font in contents:
        label = Label(frame,
                      relief='flat',
                      highlightthickness=0,
                      bg=BACKGROUND_COLOR,
                      fg=LABEL_TEXT_COLOR,
                      text=text,
                      font=font)
        label.pack_configure(padx=30, pady=10, ipadx=30, ipady=5)
    button = Button(frame,
                    relief='flat',
                    highlightthickness=0,
                    bg=ACCENT_COLOR,
                    fg=BUTTON_TEXT_COLOR,
                    activebackground=HOVER_COLOR,
                    activeforeground=BUTTON_TEXT_COLOR,
                    text='Back',
                    font=BUTTON_FONT,
                    command=go_to_scene(make_menu, tk, frame))
    button.pack_configure(padx=25, pady=20, ipadx=130, ipady=10)