Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Computer store
- from guizero import (Text, TextBox, App, ButtonGroup, Combo, PushButton, Slider,
- ListBox, CheckBox, Picture, Box)
- # Name of App
- app = App(title="Computer Store", bg="white", width=650, height=650, layout ="grid")
- # show picture (img file in same directory)
- picture = Picture(app, image="computer.jpg", align="top", width=375, height=175, grid = [0,0,3,3])
- # event functions
- # changing background/text-color from white/black to black/white
- def change_mode():
- mode = bgp_mode.value
- if mode == "Dark":
- app.bg = "black"
- app.text_color = "white"
- else:
- app.bg = "white"
- app.text_color = "black"
- # Summary of the transaction
- def make_card():
- name = text_box_1.value
- species = buttons_2.value
- adjective = combo_3.value
- colour = list_box4.value
- place = list_box5.value
- text_1.value = f"Congratulations, {name}!"
- text_2.value = f"You have purchased a {species} with {adjective} RAM"
- text_3.value = f"The colour of your {species} is {colour}."
- text_4.value = f"We hope you have enjoyed your stay with us."
- # highlight TextBox widgets when events when_mouse_enters and when_mouse_leaves are used
- # It is when mouse is over by setting its background to light blue.
- def highlight():
- text_box_1.bg = "light blue"
- def lowlight():
- text_box_1.bg = None
- # widgets used
- message5 = Text(app, text="Choose your screen type?", grid = [3,0])
- bgp_mode = ButtonGroup(app, options=["Dark", "Light"], selected="Light", command=change_mode, grid = [3,1])
- message6 = Text(app, text=" ", grid = [0,3,5,1])
- message7 = Text(app, text="Select Your Computer", grid = [0,4,3,2])
- message7.font ="Verdana"
- message7.text_size = 25
- message7.text_color = "green"
- text_n = Text(app, text = "Your name:", grid = [2,3,2,1])
- #text_1.size = 20
- text_box_1 = TextBox(app, grid = [2,4,3,2])
- # when the mouse enters the button
- text_box_1.when_mouse_enters = highlight
- # when the mouse leaves the button
- text_box_1.when_mouse_leaves = lowlight
- text_2 = Text(app, text = "Choose your equipment:", grid = [0,6])
- #text_2.size = 20
- buttons_2 = ButtonGroup(app, options = ["Desktop PC", "Laptop", "Gamer PC", "Tablet","Server", "Workstation"],
- selected = "Desktop PC", grid = [0,7])
- text_3 = Text(app, text = "RAM Memory", grid = [1,6])
- #text_3.size = 20
- combo_3 = Combo(app, options = ["4 MB", "8 MB","16 MB","32 MB"], grid = [1,7], align = "top")
- text_list4 = Text(app, text = "Select colour", grid = [2,6])
- #text_list.size = 20
- list_box4 = ListBox(app, items=["black", "white", "silver", "gold", "maroon", "gray"], selected="black", scrollbar=True, grid = [2,7])
- text_list5 = Text(app, text = "Select Operating System", grid = [3,6])
- #text_list.size = 20
- 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])
- # Event trigger
- button_6 = PushButton(app, command = make_card, text = "Finalizing your purchase", grid = [0,8])
- # Output
- text_1 = Text(app, text = "", grid = [0,10,4,1])
- text_2 = Text(app, text = "", grid = [0,11,4,1])
- text_3 = Text(app, text = "", grid = [0,12,4,1])
- text_4 = Text(app, text = "", grid = [0,14,4,1])
- text_4.font ="Verdana"
- text_4.text_size = 20
- text_4.text_color = "red"
- # Show the GUI on the screen, start listening to events.
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment