Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, PushButton, Box, Combo, Slider, MenuBar
- # Functions
- def open_file():
- with open(file_name.value, "r") as f:
- editor.value = f.read()
- open_button.hide()
- def save_file():
- with open(file_name.value, "w") as f:
- f.write(editor.value)
- save_button.hide()
- def enable_save():
- save_button.enable()
- save_button.show()
- enable_open()
- def enable_open():
- open_button.enable()
- open_button.show()
- 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_font_colour():
- editor.text_color = font_colour.value
- def change_font_courier():
- editor.font = "courier"
- def change_font_stencil():
- editor.font = "stencil"
- def change_font_times():
- editor.font = "times new roman"
- def change_font_verdana():
- editor.font = "verdana"
- def exit_app():
- app.destroy()
- app = App(title="Text Editor")
- menubar = MenuBar(app,
- toplevel=["File", "Font"],
- options=[[["open",open_file],["save",save_file],["exit",exit_app]],
- [["courier",change_font_courier],["stencil",change_font_stencil],["times new roman",change_font_times],["verdana",change_font_verdana]]])
- # Lower box and widgets
- preferences_controls = Box(app, align="top", width="fill", border=True)
- font = Combo(preferences_controls, options=["courier", "stencil", "times new roman", "verdana"], align="left", command=change_font)
- size = Slider(preferences_controls, align="left", command=change_text_size, start=10, end=18)
- font_colour = Combo(preferences_controls, align="left", command=change_font_colour, options=["black", "blue", "green", "orange", "red", "yellow"])
- editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
- # Top box and widgets
- file_controls = Box(app, align="top", width="fill")
- 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", enabled=False)
- open_button = PushButton(file_controls, text = "Open", command=open_file, align="right")
- app.display()
Add Comment
Please, Sign In to add comment