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, MenuBar , Window
- 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
- # A new functions that changes appearance or closes the app
- def big_window():
- app.width = 1200
- app.height = 800
- app.text_size = 16
- preferences_controls = Box(app, align="bottom", width="fill", border=True)
- def small_window():
- app.width = 600
- app.height = 400
- app.text_size = 8
- preferences_controls = Box(app, align="bottom", width="fill", border=True)
- def dark_theme():
- app.bg = "black"
- app.text_color = "white"
- def close_editor():
- app.destroy()
- def exit_app():
- def close_warn_window():
- warn_window.destroy()
- if save_button.enabled == True:
- warn_window = Window(app,title="File not saved", bg="red", height =40)
- save_button2 = PushButton(warn_window, text="Save", command=save_file, align="right")
- exit_button = PushButton(warn_window, text="Exit without Save", command=close_editor, align="right")
- close_warn_window = PushButton(warn_window, text="Close It", command=close_warn_window, align="left")
- if save_button.enabled == False:
- close_editor()
- app = App(title="GuiZeroTextEditor_v5" , width=900, height=700)
- # The new MenuBar
- menubar = MenuBar(app,
- toplevel=["File" ,"Editor appearance" ],
- options=[
- [ ["open",open_file], ["save",save_file],["exit",exit_app] ],
- [ ["Big window",big_window], ["Small window",small_window], ["Dark theme", dark_theme] ]
- ])
- 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