Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, Text, TextBox, PushButton, Box, Combo, CheckBox, Slider
- def open_file():
- with open(file_name.value, "r") as f:
- editor.value = f.read()
- app.info("info", "File Opened")
- save_button.disable()
- def save_file():
- with open(file_name.value, "w") as f:
- f.write(editor.value)
- app.info("info", "File Saved")
- save_button.disable()
- open_button.enable()
- def enable_save():
- open_button.disable() # changes in text - "Open Button" disabled to not lose changes
- save_button.enable()
- def change_font():
- editor.font = font.value
- def change_text_size():
- editor.text_size = size.value
- editor.resize(1, 1)
- editor.resize("fill", "fill")
- def change_text_color():
- editor.text_color = font_color.value
- def change_background_color():
- editor.bg = background_color.value
- app = App(title="GuiZeroTextEditor_v3" , width=900, height=800)
- file_controls = Box(app, align="top", width="fill", border=True)
- file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
- save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
- open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
- editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
- preferences_controls = Box(app, align="bottom", width="fill", border=True)
- font_name = Text(preferences_controls, text="Font:" , align ="left")
- font = Combo(preferences_controls, options=["Courier", "Times New Roman", "Verdana", "Piboto Condensed"], align="left", command=change_font)
- font_color_text = Text(preferences_controls, text="Font color:" , align ="left")
- font_color = Combo(preferences_controls, options=["black", "red", "green" , "blue" , "yellow"], align="left", command=change_text_color)
- background_color_text = Text(preferences_controls, text="Background color:" , align ="left")
- background_color = Combo(preferences_controls, options=["white", "black"], align="left", command=change_background_color)
- size = Slider(preferences_controls, align="left", start = 10, end = 42, command=change_text_size)
- save_button.disable() #nothing in editor - no save possibility
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement