Python Forum
Example of guizero ListBox - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Example of guizero ListBox (/thread-30648.html)



Example of guizero ListBox - jreebel - Oct-29-2020

I just started using guizero in a game I am developing using pygame. It took some experimentation to get the ListBox to do what I wanted (it's in a different file than my main. So I thought I'd share the code to help others new to the subject. The real key was putting the command function inside the ListBox creation function. This function is called from my main function right after the initial Game class was created.

from guizero import App, ListBox, Text

def get_game_type(game):
    def pick_one(value):
        game.game_type = value
        app.destroy()

    choices = None
    app = App(width=200, height=150)
    t = Text(app, 'Choose Game Type')
    choices = ListBox(app, ["New", "Saved"], height=80, width=80, command=pick_one)
    print(choices.height)
    app.display()



RE: Example of guizero ListBox - Larz60+ - Oct-29-2020

Is there a particular reason why you are using a 3rd party package for GUI (guizero) rathen than one of the proven GUI packages like Qt, tkinter, wxpython etc.?