如何使用Python中的特定按钮的按下按下循环脱离循环?

发布于 2025-01-23 08:52:24 字数 325 浏览 1 评论 0原文

我正在尝试构建一个简单的游戏,要求用户按“ P”开始,并开始生成不同的模式,直到用户按下“ S”。 Obviously what I have doesn't work, but I am not sure what to do at this point.

while ans == 'p' or ans == 'P':

    function1()
    function2()
    function3()

    if ans == 's' or ans == 'S':
        break

我已经看到了使用键盘的解决方案。

谢谢!

I am trying to build a simple game where the user is asked to press 'P' to start, and it will start generating different patterns until the user presses 'S'. Obviously what I have doesn't work, but I am not sure what to do at this point.

while ans == 'p' or ans == 'P':

    function1()
    function2()
    function3()

    if ans == 's' or ans == 'S':
        break

I have seen solutions where keyboard.is_pressed() is used but is there a way to do this without using any pre-defined function?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文