DEV Community

Cover image for number guess game with flet
watchakorn-18k
watchakorn-18k

Posted on

number guess game with flet

A simple number guessing game where players have to guess randomly generated numbers in a given range. which I created using flet which is a python module.

This number guessing game, written in Thai, is a great example of how to use the flet module in Python. In the game, players are asked to guess a randomly generated number within a given range. The range can be customized by the user, and can be as small or large as desired. After each guess, the player will be told whether their guess was too high, too low, or correct. The game will continue until the player correctly guesses the random number, at which point they will be declared the winner. Players can play as many rounds as they like, and the game will keep track of their win/loss record. Whether you're a seasoned pro or a beginner, this game is sure to provide hours of fun and challenge! The use of the flet module in this game allows for easy customization and flexibility, making it a great tool for any Python developer to have in their toolkit.

Image description

I use markdown files to assist me in writing out the instructions for how to play.

Image description

This code example

with open(self.path_markdown, "r", encoding="utf-8") as f:
            self.filemarkdown = f.read()
        self.markdown_help = ft.Markdown(
            self.filemarkdown,
            selectable=True,
            extension_set=ft.MarkdownExtensionSet.GITHUB_WEB,
        )
Enter fullscreen mode Exit fullscreen mode

I encountered a problem when trying to change the page, so I implemented a solution using a class and a method to delete all the controls within it in order to change the page.

menu_game = MenuGame()
menu_game_all = menu_game.container_main
def back_to_menu_main_from_levelScene(e):
        """
        change to menu scene
        """
        page.add(menu_game_all)
        page.remove(level_scene_all)
Enter fullscreen mode Exit fullscreen mode

This may not be the most effective way to solve this issue, but it did work for me. If anyone has a better solution, please feel free to submit a pull request.

image desc

You can access the game at this link: https://github.com/watchakorn-18k/number_guessing_game

Oldest comments (0)