Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, Text, PushButton, Box, Combo
- # function for reading files
- def open_file():
- with open(file_name.value, "r") as f:
- editor.value = f.read()
- app.title = "Now editing " + file_name.value
- # function for writing files
- def save_file():
- with open(file_name.value, "w") as f:
- f.write(editor.value)
- app.title = file_name.value + " successfully saved!"
- def bg_col():
- if cmb_bg.value == "Calm":
- editor.bg = "#fcdd88"
- editor.text_color = "#855600"
- elif cmb_bg.value == "Clear":
- editor.bg = "#ffffff"
- editor.text_color = "#2222ff"
- elif cmb_bg.value == "Hacker":
- editor.bg = "#000000"
- editor.text_color = "#4cf000"
- def font_up():
- editor.text_size = editor.text_size + 2
- def font_down():
- editor.text_size = editor.text_size - 2
- app = App(title="texteditor")
- #Box to house the visual options
- box_appearance_controls = Box(app, layout="auto", align="top", width="fill", height=50)
- #Widgets for background colour
- lbl_background = Text(box_appearance_controls, text="What's your mood?", align="left")
- cmb_bg = Combo(box_appearance_controls, options=["Clear", "Hacker", "Calm"], align="left", height="fill", command=bg_col)
- #Widgets for font size
- lbl_size = Text(box_appearance_controls, text=" Font size: ", align="left")
- box_spacer = Box(box_appearance_controls, width=25, align="left", height="fill")
- btn_font_up = PushButton(box_appearance_controls, command=font_up, text="+", align="left")
- box_spacer = Box(box_appearance_controls, width=25, align="left", height="fill")
- btn_font_down = PushButton(box_appearance_controls, command=font_down, text="-", align="left")
- # create a TextBox which is not in the box and fills the rest of the GUI
- editor = TextBox(app, multiline=True, height="fill", width="fill", scrollbar=True)
- # create a box to house the controls, we want the box to span the entire width
- file_controls = Box(app, align="bottom", width="fill")
- # create a TextBox for the file name
- file_name = TextBox(file_controls, text="type file name here (add .txt to the end)", width=50, align="left")
- # create an open button which uses the open_file function
- open_button = PushButton(file_controls, text="Open", align="right", command=open_file)
- box_spacer = Box(file_controls, width=15, align="right")
- # create a save button which uses the save_file function
- save_button = PushButton(file_controls, text="Save", align="right", command=save_file)
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement