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
 9SCREEN_WIDTH = 500
10SCREEN_HEIGHT = 500
11SCREEN_TITLE = "Resizing Window Example"
12START = 0
13END = 2000
14STEP = 50
15
16
17class MyGame(arcade.Window):
18    """
19    Main application class.
20    """
21
22    def __init__(self, width, height, title):
23        super().__init__(width, height, title, resizable=True)
24
25        arcade.set_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, and default to 0,0 at the center and the
31        # 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        arcade.start_render()
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}", 5, y, arcade.color.BLACK, 12, anchor_x="left", anchor_y="bottom")
46            i += 1
47
48        # Draw the x labels.
49        i = 1
50        for x in range(START + STEP, END, STEP):
51            arcade.draw_point(x, 0, arcade.color.BLUE, 5)
52            arcade.draw_text(f"{x}", x, 5, arcade.color.BLACK, 12, anchor_x="left", anchor_y="bottom")
53            i += 1
54
55
56def main():
57    MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
58    arcade.run()
59
60
61if __name__ == "__main__":
62    main()