maroph

heroname2.py

Dec 7th, 2019
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. from guizero import App, ButtonGroup, CheckBox, Combo, info, ListBox, Picture, PushButton, Slider, Text
  2.  
  3. # https://lawsie.github.io/guizero/layout/\
  4. app = App(title="Hero name generator", layout="grid")
  5. app.bg = 'white'
  6. app.height = 750
  7. app.width = 400
  8.  
  9.  
  10. def btn_go_clicked():
  11.     name = "Your "
  12.     if checkbox.value == 1:
  13.         name += " SUPER "
  14.     if listbox.value is not None:
  15.         for item in listbox.value:
  16.             name += item + " "
  17.     name += "hero name:"
  18.     info(name, bg_adjective.value + " " + combo_color.value + " " + combo_animal.value + " at slip level " + str(slider.value))
  19.  
  20. def toggle_dark_mode():
  21.     if cb_dark.value != 0:
  22.         app.bg = 'silver'
  23.     else:
  24.         app.bg = 'white'
  25.  
  26.  
  27. # image: http://www.marochess.de/imgs/dntpanic.gif
  28. picture = Picture(app, image='./dntpanic.gif', grid=[0, 0, 2, 1])
  29.  
  30. lbl_adjective = Text(app, text="Choose an adjective...", grid=[0,1], align="left")
  31. bg_adjective = ButtonGroup(app, options=["Busy", "Crazy", "Crying", "Funny", "Happy", "Lazy", "Powerful"], selected="Powerful", grid=[1,1], align="left")
  32.  
  33. lbl_color = Text(app, text="Enter a color...", grid=[0,2], align="left")
  34. combo_color = Combo(app, options=["Black", "Blue", "Green", "Red", "Pink", "Yellow", "Violet"], selected="Pink", grid=[1,2], align="left")
  35.  
  36. lbl_animal = Text(app, text="Pick an animal...", grid=[0,3], align="left")
  37. combo_animal = Combo(app, options=["Bear", "Deer", "Hamster", "Panther", "Skunk", "Snake"], selected="Hamster", grid=[1,3], align="left")
  38.  
  39. lbl_slider = Text(app, text="Slip sliding away...", grid=[0,4], align="left")
  40. slider = Slider(app, start=0, end=10, grid=[1,4], align="left")
  41.  
  42. # nonsense text, just added to show the functionality
  43. lbl_listbox = Text(app, text="Extra name labeling", grid=[0,5], align="left")
  44. listbox = ListBox(app, items=["LB1", "LB2", "LB3", "LB4"], multiselect=True, height="10", width="30", scrollbar=True, grid=[1,5], align="left")
  45.  
  46.  
  47. checkbox = CheckBox(app, text="Add SUPER to hero to name", grid=[0,6], align="left")
  48.  
  49. cb_dark = CheckBox(app, text="Dark mode", command=toggle_dark_mode, grid=[0,7], align="left")
  50.  
  51. btn_go = PushButton(app, command=btn_go_clicked, text="Generate hero name", grid=[0,8, 2 ,1])
  52.  
  53. app.display()
Advertisement
Add Comment
Please, Sign In to add comment