Advertisement
JDpaste

Python GUI guizero: Box layout: Box in Box

Sep 30th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.63 KB | None | 0 0
  1. # guizero - Hero name generator .. Box in Box
  2. # Design principles .. repetition, proximity, ...
  3. from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, Box
  4. app = App(title="Hero-o-matic", width=600, height=690)
  5. app.bg = "#CCCC00"
  6.  
  7. # Function definitions for your events go here.
  8. def make_hero_name():
  9.     adjective = bgp_adjective.value
  10.     colour = txt_cText.value
  11.     animal = cmb_animal.value
  12.     hero = adjective + " " + colour + " " + animal
  13.     lbl_output.value = "You are... The " + hero + "."
  14.  
  15. # STYLING: define some Colour constants
  16. cSubHead   = "#FFFFFF"
  17. cSubHeadBg = "#000000"
  18. txtSizeSubHead = 14
  19. widthSubHead   = 28
  20. #------------
  21. # GUI widgets
  22. h1 = Text(app, text="Hero-o-matic name builder", size=26, font="Times New Roman")
  23.  
  24. boxForm = Box(app, width=400, height=600)
  25. boxForm.bg = "cyan"
  26. # now add widgets inside 'form' Box
  27.  
  28. boxAdj = Box(boxForm, width="fill", height=190)
  29. boxAdj.bg = "#74CC9F"
  30. boxAdj.text_color = "#123456"
  31.  
  32. message1 = Text(boxAdj, text="Please choose an adjective ..", width=widthSubHead )
  33. message1.text_color = cSubHead
  34. message1.bg = cSubHeadBg
  35. message1.text_size = txtSizeSubHead
  36.  
  37. bgp_adjective = ButtonGroup(boxAdj, options=["Amazing", "Bonny", "Charming", "Delightful", "Vundebar"], selected="Amazing")
  38. #-------------
  39. boxColor = Box(boxForm, width="fill", height=90)
  40. boxColor.bg = "#54AA7F"
  41. boxColor.text_color = "white"
  42.  
  43. message2 = Text(boxColor, text="Please enter a colour name ..", width=widthSubHead )
  44. message2.text_color = cSubHead
  45. message2.bg = cSubHeadBg
  46. message2.text_size = txtSizeSubHead
  47.  
  48. vertSpace01 = Text(boxColor, text=" ", width="fill", size=12 )
  49. txt_cText = TextBox(boxColor)
  50. txt_cText.bg="white"
  51. txt_cText.text_color = "black"
  52. txt_cText.text_size = 18
  53. #-----------
  54. boxAni = Box(boxForm, width="fill", height=90)
  55.  
  56. message3 = Text(boxAni, text="Please pick an animal ..", width=widthSubHead )
  57. message3.text_color = cSubHead
  58. message3.bg = cSubHeadBg
  59. message3.text_size = txtSizeSubHead
  60. vertSpace02 = Text(boxAni, text=" ", width="fill", size=12 )
  61.  
  62. cmb_animal = Combo(boxAni, options=["Aardvark", "Badger", "Cat", "Dog", "Dolphin", "Velociraptor"], selected="Aardvark", width=20)
  63. cmb_animal.text_color = "#FFFFFF"
  64. cmb_animal.bg = "#FF0000"
  65.  
  66. btn_make_name = PushButton(boxForm, text='Make me a hero', command= make_hero_name )
  67. btn_make_name.bg = "#EE66EE"
  68. btn_make_name.text_color = "white"
  69. #-----------
  70. boxOut = Box(boxForm, width="fill", height=90)
  71.  
  72. lbl_output = Text(boxOut, text="A hero name will appear here", align="bottom")
  73.  
  74. # Set up event triggers here
  75.  
  76. # Show the GUI on the screen, start listening to events.
  77. txt_cText.focus()
  78. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement