Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, PushButton, Box, Combo, MenuBar
- # 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():
- with open(file_name.value, "w") as f:
- f.write(editor.value)
- # Disable the save_button
- save_button.hide()
- # A new function that closes the app
- def exit_app():
- app.destroy()
- # function for change size font
- def font_button():
- editor.font=font_combo.value
- # function for change align DOES NOT WORK
- def align_button():
- editor.align=align_combo.value
- # function for change color
- def color_button():
- editor.text_color=color_combo.value
- #if color_combo.value=="red":
- #size_combo.disable()
- #else:
- #size_combo.enable()
- # function for change font
- def size_button():
- editor.text_size=size_combo.value
- editor.resize(1, 1)
- editor.resize("fill", "fill")
- def enable_save():
- save_button.show()
- app = App(title="texteditor")
- # The new MenuBar
- menubar = MenuBar(app,
- toplevel=["File","Edit"],
- options=[
- [["open",open_file],["save",save_file],["exit",exit_app]],
- [["Font",font_button],["Size",size_button],["Align",align_button],["Color",color_button], ]
- ])
- # create a box to house the controls, we want the box to span the entire width of the app
- file_controls = Box(app, align="top", width="fill", border=True)
- format_controls=Box(app, align="top", width="fill")
- # create a TextBox for the file name
- file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
- # create a save button which uses the save_file function
- save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
- # create an open button which uses the open_file function
- open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
- # create an open button which uses the open_file function
- color_combo = Combo(format_controls, options=["red","green","blue","cyan","black"], selected="black", align="right", command=color_button)
- # create an open button which uses the open_file function
- font_combo = Combo(format_controls, options=["Arial", "Helevetica","Courier"], selected="Courier", align="right", command=font_button)
- # create an open button which uses the open_file function
- size_combo = Combo(format_controls, options=[6,8,10,12,14,16,18,20], selected="10", align="right", command=size_button)
- # create an open button which uses the open_file function
- align_combo = Combo(format_controls, options=["left","right","top","bottom"], width=40,selected="left", align="right", command=align_button)
- # 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)
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement