Advertisement
davidhellam

Python: Hero-o-matic 2

Aug 10th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1. # guizero - Hero name generator
  2. from guizero import App, Text, ButtonGroup, Combo, PushButton, TextBox, Picture, Slider
  3.  
  4. app = App(title="My Version of Hero-o-matic", width=720, height=640, bg="#ffcccc")
  5.  
  6. # Function definitions for your events go here.
  7.  
  8. def validateColour(colour):
  9.     validColours = ["pink","magenta","red","orange","yellow","green","cyan","blue","violet","brown","grey","black","white"]
  10.     colourdefs=[(255,204,204),(255,0,255),(255,0,0),(255,153,51),(255,255,0),(51,255,51),(0,255,255),(0,0,255),(153,0,204),(102,51,51),(153,153,153),(0,0,0),(255,255,255)]
  11.     for counter in range(len(validColours)):
  12.         if validColours[counter]==colour.lower():
  13.             txt_output.text_color=colourdefs[counter]
  14.  
  15. def makeIt():
  16.     heroName = tbx_nam.value+", the "+btg_adj.value+" "+tbx_col.value+" "+cmb_ani.value
  17.     txt_output.value = heroName
  18.     txt_output.show()
  19.     validateColour(tbx_col.value)
  20.  
  21. def darklite():
  22.     darkness = int(sld_darkness.value)*3*17
  23.     app.bg=(255,darkness,darkness)
  24.     picnames=["ebook-penguin.png","judo-penguin.png","VR_penguin.png","Christmas-in-July-penguin.png","veggie-penguin.png","painter-penguin.png"]
  25.     img_header.image=picnames[int(sld_darkness.value)]
  26.  
  27. # Your GUI widgets go here
  28. txt_title = Text(app,"Hero Name Generator", size=36)
  29. img_header = Picture(app,"veggie-penguin.png")
  30. sld_darkness = Slider(app,start=0,end=5,horizontal=True)
  31. sld_darkness.value=4
  32.  
  33.  
  34. txt_nam = Text(app, text="Type your name:")
  35. tbx_nam = TextBox(app, width = 15)
  36.  
  37. txt_adj = Text(app, text="Choose an adjective:")
  38. btg_adj = ButtonGroup(app, options=["Artful", "Brazen", "Confusing", "Droll", "Engaging"], selected="Amazing")
  39.  
  40. txt_col = Text(app, text="Enter a colour:")
  41. tbx_col = TextBox(app, width = 15)
  42.  
  43. txt_ani = Text(app, text="Pick an animal")
  44. cmb_ani = Combo(app, options=["Ankylosaurus", "Brachiosaurus", "Ceratosaurus", "Dimetrodon", "Einiosaurus"], selected="Aardvark", width=20)
  45.  
  46. btn_makeName = PushButton(app, text='Make my hero name now',command=makeIt)
  47. txt_output = Text(app, text="Hero name will appear here", size=28)
  48. txt_output.hide()
  49.  
  50. # Set up event triggers here
  51. sld_darkness.when_mouse_dragged = darklite
  52.  
  53. # Show the GUI on the screen, start listening to events.
  54. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement