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        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    MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
63    arcade.run()
64
65
66if __name__ == "__main__":
67    main()