Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, PushButton, Box, Combo, Slider, MenuBar
- # function for reading files
- def open_file():
- # Use filedialog introduced in guizero 1.1.0, may need to alter check to None if bug is fixed
- file_name_open = app.select_file(title="Select file", folder=".", filetypes=[["All files", "*.*"]], save=False)
- if file_name_open is not "":
- with open(file_name_open, "r") as f:
- editor.value = f.read()
- file_name.value = file_name_open
- # function for writing files
- def save_file():
- # Use filedialog introduced in guizero 1.1.0, may need to alter check to None if bug is fixed
- file_name_save = app.select_file(title="Select file", folder=".", filetypes=[["All files", "*.*"]], save=True)
- if file_name_save is not "":
- with open(file_name_save, "w") as f:
- f.write(editor.value)
- save_button.disable()
- file_name.value = file_name_save
- def enable_save():
- save_button.enable()
- def change_font():
- editor.font = font.value
- colour.font = font.value
- font.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_text_colour():
- editor.text_color = colour.value
- font.text_color = colour.value
- colour.text_color = colour.value
- def edit_cut():
- pass
- def edit_copy():
- pass
- def edit_paste():
- pass
- def edit_selectall():
- pass
- def tools_settings():
- pass
- def tools_help():
- app.info("help", "you will find help at www.MyNotepad.not.com")
- def tools_about():
- app.info("about","v 0.000001 \n created by : me \n year : 2021")
- # A new function that closes the app
- def exit_app():
- app.destroy()
- app = App(title="My simple notepad")
- # The new MenuBar
- menubar = MenuBar(app,
- toplevel=["File", "Edit", "Tools"],
- options=[
- [ ["open", open_file], ["save", save_file], ["exit", exit_app] ],
- [ ["cut", edit_cut], ["copy", edit_copy], ["paste", edit_paste], ["select all", edit_selectall] ],
- [ ["settings", tools_settings], ["help", tools_help], ["about", tools_about] ]
- ])
- # 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")
- preferences_controls = Box(app, align="top", width="fill", border=True)
- file_controls2 = Box(app, align="bottom", width="fill")
- # File name and open
- file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
- open_button = PushButton(file_controls, text="Open", align="right", command = open_file)
- # font choice
- font = Combo(preferences_controls, options=["ariel", "courier", "times new roman", "verdana"], align="left", command=change_font)
- colour = Combo(preferences_controls, options=["black", "gray", "light gray", "white", "red", "green", "blue"], align="left", command = change_text_colour)
- size = Slider(preferences_controls, align="left", command=change_text_size, start=10, end=18)
- # TheTextBox, 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)
- # Save
- save_button = PushButton(file_controls2, text="Save", align="right", command = save_file)
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement