Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import *
- app = App(title="texteditor")
- # 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():
- # Disable the save_button
- save_button.hide()
- with open(file_name.value, "w") as f:
- f.write(editor.value)
- def enable_save():
- save_button.show()
- def change_font():
- editor.font = font.value
- def change_text_size():
- editor.text_size = 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")
- def change_color ():
- editor.text_color = font_c.value
- # A new function that closes the app
- def exit_app():
- if save_button.visible==True:
- app.info("Warning!", "You have not saved the changes")
- else:
- app.destroy()
- def undo():
- app.info("Information", "This function has not been implemented yet!")
- def copy():
- app.info("Information", "This function has not been implemented yet!")
- def cut():
- app.info("Information", "This function has not been implemented yet!")
- def paste():
- app.info("Information", "This function has not been implemented yet!")
- def find():
- app.info("Information", "This function has not been implemented yet!")
- def replace():
- app.info("Information", "This function has not been implemented yet!")
- def help_function():
- app.info("Information", "This function has not been implemented yet!")
- def about():
- app.info("Information", "This function has not been implemented yet!")
- def make_dark_mode ():
- if chk_dark.value == 1:
- app.bg="black"
- app.text_color = "white"
- else:
- app.bg="white"
- app.text_color = "black"
- # new Box for font, size and color
- menubar = MenuBar(app,
- toplevel=["File","Edit","Format","Help"],
- options=[[["open",open_file],["save",save_file],["exit",exit_app]],
- [["Undo",undo],["Copy",copy], ["Cut",cut], ["Paste",paste], ["Find",find],["Replace",replace]],
- [["Font",change_font]],
- [["Help",help_function], ["About", about]]])
- preferences_controls = Box(app, width="fill", border=True)
- font = Combo(preferences_controls, options=["Courier", "Times new roman", "Verdana", "Calibri", "Tahoma"], align="left", command=change_font)
- size = Slider(preferences_controls, align="left", command=change_text_size, start=10, end=18)
- font_c = Combo(preferences_controls, options=["Red", "Green", "Blue", "White", "Black", "Gray"], align="left", command=change_color)
- # box to house the controls, we want the box to span the entire width of the app
- file_controls = Box(app, align="bottom", width="fill")
- # TextBox for the file name
- file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
- # save button which uses the save_file function
- save_button = PushButton(file_controls, text="Save", command=save_file, align="right", visible=False)
- # open button which uses the open_file function
- open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
- # text
- editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
- box_dark=Box(app)
- chk_dark = CheckBox (box_dark, text="Dark Mode", command=make_dark_mode)
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement