简体   繁体   English

在 PyGame 中弹出消息框

[英]Pop up message box in PyGame

I want to create a pop up window inside the game which will display result for a small game, if you click OK, the game continues, but that doesn't matter.我想在游戏中创建一个弹出窗口,显示一个小游戏的结果,如果你点击确定,游戏会继续,但这并不重要。 How do you even create such box so it will pop up when I call it?你甚至如何创建这样的框,以便在我调用它时它会弹出? I read question with pgu , what is pgu ?我读了pgu问题, pgupgu Is it another external library?它是另一个外部图书馆吗?

I used tkinter and created a message box,我使用tkinter并创建了一个消息框,

from tkinter import *
from tkinter import messagebox
Tk().wm_withdraw() #to hide the main window
messagebox.showinfo('Continue','OK')

You can treat popup window like another sprite in Pygame.您可以将弹出窗口视为 Pygame 中的另一个精灵。

Create class with draw() , update() , handle_event() and use it similar to Player and Enemy .使用draw()update()handle_event()创建类并使用它类似于PlayerEnemy

Simple example with own Button in PyGame 在 PyGame 中使用自己的Button 的简单示例


You may also use one of PyGame modules for GUI but some of themy may need changes in code because they run own event loop.您也可以将 PyGame 模块之一用于 GUI,但其中一些模块可能需要更改代码,因为它们运行自己的事件循环。

Example GUIs GUI 示例

More on PyGame page: PyGame GUIs更多关于 PyGame 页面: PyGame GUIs

You can use PyZenity , installable via Pip.您可以使用PyZenity ,可通过 Pip 安装。 Then, you can just do:然后,你可以这样做:

from PyZenity import *
cancel = Question('Continue game?')

you can use pyautogui alert or confirm.您可以使用 pyautogui 警报或确认。

    if something_happens:
       pyautogui.alert("you have done this")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM