Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? Is it another external library?

like image 277
Simeon Aleksov Avatar asked Jan 13 '17 16:01

Simeon Aleksov


People also ask

How do I show a pop up message in Python?

In order to create a Python popup message, you can use Tkinter message prompts. First, you need to import the Tkinter package to use this method. The Tkinter message box module offers different options and configurations.

How do you make a pop up box in Tkinter?

Popup window in Tkinter can be created by defining the Toplevel(win) window. A Toplevel window manages to create a child window along with the parent window. It always opens above all the other windows defined in any application.

Does pygame have a GUI?

Pygame GUI is a module to help you make graphical user interfaces for games written in pygame. The module is firmly forward looking and is designed to work on Pygame 2 and Python 3.


2 Answers

I used tkinter and created a message box,

from tkinter import *
from tkinter import messagebox
Tk().wm_withdraw() #to hide the main window
messagebox.showinfo('Continue','OK')
like image 138
Simeon Aleksov Avatar answered Sep 26 '22 19:09

Simeon Aleksov


You can treat popup window like another sprite in Pygame.

Create class with draw(), update(), handle_event() and use it similar to Player and Enemy.

Simple example with own Button in PyGame


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.

Example GUIs

  • PGU

  • OcempGUI

More on PyGame page: PyGame GUIs

like image 40
furas Avatar answered Sep 23 '22 19:09

furas