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"""
 7from __future__ import annotations
 8
 9import arcade
10
11SCREEN_WIDTH = 500
12SCREEN_HEIGHT = 500
13SCREEN_TITLE = "Resizing Window Example"
14START = 0
15END = 2000
16STEP = 50
17
18
19class MyGame(arcade.Window):
20    """
21    Main application class.
22    """
23
24    def __init__(self, width, height, title):
25        super().__init__(width, height, title, resizable=True)
26
27        self.background_color = arcade.color.WHITE
28
29    def on_resize(self, width, height):
30        """ This method is automatically called when the window is resized. """
31
32        # Call the parent. Failing to do this will mess up the coordinates,
33        # and default to 0,0 at the center and the edges being -1 to 1.
34        super().on_resize(width, height)
35
36        print(f"Window resized to: {width}, {height}")
37
38    def on_draw(self):
39        """ Render the screen. """
40
41        self.clear()
42
43        # Draw the y labels
44        i = 0
45        for y in range(START, END, STEP):
46            arcade.draw_point(0, y, arcade.color.BLUE, 5)
47            arcade.draw_text(f"{y}",
48                             5, y,
49                             arcade.color.BLACK,
50                             12,
51                             anchor_x="left", anchor_y="bottom")
52            i += 1
53
54        # Draw the x labels.
55        i = 1
56        for x in range(START + STEP, END, STEP):
57            arcade.draw_point(x, 0, arcade.color.BLUE, 5)
58            arcade.draw_text(f"{x}", x, 5, arcade.color.BLACK, 12,
59                             anchor_x="left", anchor_y="bottom")
60            i += 1
61
62
63def main():
64    MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
65    arcade.run()
66
67
68if __name__ == "__main__":
69    main()