Resizable Window

Screenshot of resizable window
resizable_window.py
 1"""
 2Example showing how handle screen resizing.
 3
 4If Python and Arcade are installed, this example can be run from the command line with:
 5python -m arcade.examples.resizable_window
 6"""
 7import arcade
 8
 9WINDOW_WIDTH = 500
10WINDOW_HEIGHT = 500
11WINDOW_TITLE = "Resizing Window Example"
12START = 0
13END = 2000
14STEP = 50
15
16
17class GameView(arcade.View):
18    """
19    Main application class.
20    """
21
22    def __init__(self):
23        super().__init__()
24
25        self.background_color = arcade.color.WHITE
26
27    def on_resize(self, width, height):
28        """ This method is automatically called when the window is resized. """
29
30        # Call the parent. Failing to do this will mess up the coordinates,
31        # and default to 0,0 at the center and the edges being -1 to 1.
32        super().on_resize(width, height)
33
34        print(f"Window resized to: {width}, {height}")
35
36    def on_draw(self):
37        """ Render the screen. """
38
39        self.clear()
40
41        # Draw the y labels
42        i = 0
43        for y in range(START, END, STEP):
44            arcade.draw_point(0, y, arcade.color.BLUE, 5)
45            arcade.draw_text(f"{y}",
46                             5, y,
47                             arcade.color.BLACK,
48                             12,
49                             anchor_x="left", anchor_y="bottom")
50            i += 1
51
52        # Draw the x labels.
53        i = 1
54        for x in range(START + STEP, END, STEP):
55            arcade.draw_point(x, 0, arcade.color.BLUE, 5)
56            arcade.draw_text(f"{x}", x, 5, arcade.color.BLACK, 12,
57                             anchor_x="left", anchor_y="bottom")
58            i += 1
59
60
61def main():
62    """ Main function """
63    # Create a window class. This is what actually shows up on screen
64    window = arcade.Window(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE, resizable=True)
65
66    # Create the GameView
67    game = GameView()
68
69    # Show GameView on screen
70    window.show_view(game)
71
72    # Start the arcade game loop
73    arcade.run()
74
75
76if __name__ == "__main__":
77    main()