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?
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.
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.
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.
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')
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With