Python Forum
Menus, buttons and other widgets for Pygame
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Menus, buttons and other widgets for Pygame
#1
I've started coding a turn based game in python and now want to start work on the UI. pygame seemed like the natural choice. I've gone through the tutorials and everything makes sense to me :)

What I really need though is a package that has buttons drop down menus, text fields, tables, etc... pre-built, a bit like the tkinter stuff, so I dont have to do them myself entirely from scratch. I had a look on the pygame website for this, and a bunch of such packages do exist, but most of them have been abandoned for a decade. MenuClass and KezMenu seem the most promising.

Are the others I should have a look at? Which do you recommend? Or should I be using a completely different package to pygame for this?
Reply
#2
Suggest you look for a game on PyPi https://pypi.python.org/pypi
The requirements should show pygame if used
then download the software for your example
Reply
#3
(Apr-14-2017, 03:12 PM)Olleus Wrote: What I really need though is a package that has buttons drop down menus, text fields, tables, etc... pre-built, a bit like the tkinter stuff
That is a big downfall for pygame. There is no default UI like there is for tkinter. I would say 90% of devs using pygame make their own UI. 
Here is an example of all the UI buttons we had to create for this game
https://github.com/metulburr/pyroller/bl.../labels.py

there are some libs in pygame.org
https://www.pygame.org/project/108
https://www.pygame.org/project/740
https://www.pygame.org/project/393
etc.
but i still prefer to make my own. Then i can tweak it the way i want it to work. To be honest i wouldnt recommend any of them. All seem to fall short in some manner.
Recommended Tutorials:
Reply
#4
So is the basic idea that I should mostly do it myself, using other's codes for examples?

I was considering using Kivy otherwise, it has been recommended by others but I feel like it does too much extra that I don't need. What about pyglet? I've heard about it but havent figured out what it actually does...
Reply
#5
pyglet also doesnt have any UI like buttons as well (i think). Pyglet is like pygame. I feel like the community is smaller in pyglet than in pygame. 

Kivy is mainly for mobile devices and actually has its own language. Most of the time you are not typing out python syntax but kivy syntax. Here is a small example of an input box and label in kivy
<ScatterTextWidget>:
    orientation: 'vertical'
    TextInput:
        id: my_textinput
        font_size: 150
        size_hint_y: None
        height: 200
        text: 'default'
    FloatLayout:
        Scatter:
            Label:
                text: my_textinput.text
                font_size: 150
while here is the python script that runs it
from kivy.app import App

from kivy.uix.scatter import Scatter
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout

class ScatterTextWidget(BoxLayout):
    pass

class MainApp(App):
    def build(self):
        return ScatterTextWidget()

if __name__ == "__main__":
    MainApp().run()
As you can see the meat of the program is in the kivy syntax
Quote:So is the basic idea that I should mostly do it myself, using other's codes for examples?
Yeah its kinda stupid that they havent implemented a basic UI system. You do get use to it. Once you find good code, and understand it, you dont have to change it much....if ever. I have always used the same button class for years in all my games without changing the button code because its flexible to handle multiple situations. You just have to keep uploading it to each of your games instead of expecting it to be in pygame. 

check out @[Mekire] github
https://github.com/Mekire

It has a lot of basic examples for learning and as well as some repos of good coded flexible UI tools off the bat.
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] pygame-manu : using controller buttons to move around menu mlw19mlw91 2 1,610 Mar-12-2023, 01:55 PM
Last Post: deanhystad
  Pygame - Images As Buttons vman44 3 12,966 Mar-20-2020, 08:13 PM
Last Post: vman44
  [pygame] Equiping inventory slots with invisible buttons SheeppOSU 6 4,726 Apr-26-2019, 08:45 PM
Last Post: SheeppOSU
  Problems with loading buttons (pygame) SheeppOSU 2 3,098 Apr-12-2019, 08:04 PM
Last Post: SheeppOSU
  Buttons in PyGame mzmingle 4 13,053 Oct-09-2018, 05:19 PM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020