crzcas

computer store

Mar 7th, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.42 KB | None | 0 0
  1. # Computer store
  2.  
  3. from guizero import (Text, TextBox, App, ButtonGroup, Combo, PushButton, Slider,
  4.                     ListBox, CheckBox, Picture, Box)
  5.  
  6. # Name of App
  7. app = App(title="Computer Store", bg="white", width=650, height=650, layout ="grid")
  8.  
  9. # show picture (img file in same directory)
  10. picture = Picture(app, image="computer.jpg", align="top", width=375, height=175, grid = [0,0,3,3])
  11.  
  12.  
  13. # event functions
  14.  
  15. # changing background/text-color from white/black to black/white
  16. def change_mode():
  17.     mode = bgp_mode.value
  18.     if mode == "Dark":
  19.         app.bg = "black"
  20.         app.text_color = "white"
  21.     else:
  22.         app.bg = "white"
  23.         app.text_color = "black"
  24.  
  25. # Summary of the transaction
  26. def make_card():
  27.     name = text_box_1.value
  28.     species = buttons_2.value
  29.     adjective = combo_3.value
  30.     colour = list_box4.value
  31.     place = list_box5.value
  32.     text_1.value = f"Congratulations, {name}!"
  33.     text_2.value = f"You have purchased a {species} with {adjective} RAM"
  34.     text_3.value = f"The colour of your {species} is {colour}."
  35.     text_4.value = f"We hope you have enjoyed your stay with us."
  36.  
  37. # highlight TextBox widgets when events when_mouse_enters and when_mouse_leaves are used
  38. # It is when mouse is over by setting its background to light blue.
  39. def highlight():
  40.     text_box_1.bg = "light blue"
  41.  
  42. def lowlight():
  43.     text_box_1.bg = None
  44.  
  45.  
  46. # widgets used
  47. message5 = Text(app, text="Choose your screen type?", grid = [3,0])
  48. bgp_mode = ButtonGroup(app, options=["Dark", "Light"], selected="Light", command=change_mode, grid = [3,1])
  49.  
  50. message6 = Text(app, text="                          ", grid = [0,3,5,1])
  51. message7 = Text(app, text="Select Your Computer", grid = [0,4,3,2])
  52. message7.font ="Verdana"
  53. message7.text_size = 25
  54. message7.text_color = "green"
  55.  
  56. text_n = Text(app, text = "Your name:", grid = [2,3,2,1])
  57. #text_1.size = 20
  58. text_box_1 = TextBox(app, grid = [2,4,3,2])
  59. # when the mouse enters the button
  60. text_box_1.when_mouse_enters = highlight
  61. # when the mouse leaves the button
  62. text_box_1.when_mouse_leaves = lowlight
  63.  
  64. text_2 = Text(app, text = "Choose your equipment:", grid = [0,6])
  65. #text_2.size = 20
  66. buttons_2 = ButtonGroup(app, options = ["Desktop PC", "Laptop", "Gamer PC", "Tablet","Server", "Workstation"],
  67. selected = "Desktop PC", grid = [0,7])
  68.  
  69. text_3 = Text(app, text = "RAM Memory", grid = [1,6])
  70. #text_3.size = 20
  71. combo_3 = Combo(app, options = ["4 MB", "8 MB","16 MB","32 MB"], grid = [1,7], align = "top")
  72.  
  73. text_list4 = Text(app, text = "Select colour", grid = [2,6])
  74. #text_list.size = 20
  75. list_box4 = ListBox(app, items=["black", "white", "silver", "gold", "maroon", "gray"], selected="black", scrollbar=True, grid = [2,7])
  76.  
  77. text_list5 = Text(app, text = "Select Operating System", grid = [3,6])
  78. #text_list.size = 20
  79. list_box5 = ListBox(app, items=["MS-Windows", "Ubuntu", "Mac OS", "Fedora", "Solaris", "Free BSD", "Chrome OS", "CentOS"], selected="4-Poster-bed", scrollbar=True, grid = [3,7])
  80.  
  81. # Event trigger
  82. button_6 = PushButton(app, command = make_card, text = "Finalizing your purchase", grid = [0,8])
  83.  
  84. # Output
  85. text_1 = Text(app, text = "", grid = [0,10,4,1])
  86. text_2 = Text(app, text = "", grid = [0,11,4,1])
  87. text_3 = Text(app, text = "", grid = [0,12,4,1])
  88. text_4 = Text(app, text = "", grid = [0,14,4,1])
  89. text_4.font ="Verdana"
  90.  
  91. text_4.text_size = 20
  92. text_4.text_color = "red"
  93.  
  94. # Show the GUI on the screen, start listening to events.
  95. app.display()
Advertisement
Add Comment
Please, Sign In to add comment