Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, PushButton, Box, Combo, Slider, info, MenuBar
- app = App(title="texteditor")
- #def main():
- # disable_save()
- # function for reading files
- def open_file():
- with open(file_name.value, "r") as f:
- editor.value = f.read()
- # function for writing files
- def save_file():
- # button_save.visible = False
- with open(file_name.value, "w") as f:
- f.write(editor.value)
- button_save.disable()
- # info("Hide Button","Save button is hided!")
- # button_save.visible = True
- def enable_save():
- button_save.enable()
- def disable_save():
- button_save.disable()
- def exit_app():
- app.destroy()
- def change_font_type():
- editor.font = cmb_font_type.value
- enable_save()
- def change_font_size():
- # editor.text_size = cmb_font_size.value
- editor.text_size = slider_font_size.value
- # resize the widget because if the text is made bigger, this might affect the size of the TextBox so guizero needs to know how to maintain the intended layout
- editor.resize(1, 1)
- editor.resize("fill", "fill")
- enable_save()
- def change_font_color():
- editor.text_color = cmb_font_color.value
- enable_save()
- def func_help():
- info ("TextZero Help", "This is your HELP! :)")
- def func_about():
- info ("TextZero", "Made by us!")
- # The new MenuBar
- menubar = MenuBar(app,
- toplevel=["File", "Help"],
- options=[
- [["Open",open_file],["Save",save_file],["Exit",exit_app]],
- [["Help", func_help], ["About", func_about]]
- ])
- box_ribbon = Box(app, align="top", width="fill")
- # create a box to house the controls, we want the box to span the entire width of the app
- box_file_controls = Box(box_ribbon, align="top", width="fill")
- # create an open button which uses the open_file function
- button_open = PushButton(box_file_controls, text="Open", align="left", command=open_file)
- # create a save button which uses the save_file function
- button_save = PushButton(box_file_controls, text="Save", align="left", enabled = False, command=save_file)
- # create a TextBox for the file name
- file_name = TextBox(box_file_controls, text="text_file.txt", width=50, align="right")
- box_font_controls = Box(box_ribbon, align="top", width="fill")
- cmb_font_type = Combo (box_font_controls, options=["courier", "helvetica", "times new roman"], align="left", command=change_font_type, width = 16)
- cmb_font_color = Combo (box_font_controls, options=["black", "red", "blue", "green"], align="left", command=change_font_color, width = 8)
- slider_font_size = Slider(box_font_controls, align="left", start = 8, end = 42, command=change_font_size)
- # cmb_font_size = Combo (box_font_controls, options=["8", "12", "16", "24"], align="left", command=change_font_size, width = 4)
- # 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", command=enable_save)
- # main()
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment