Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Replace the original import line with this:
- from guizero import App, Text, TextBox, PushButton, Box, Combo, CheckBox, Slider
- 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():
- with open(file_name.value, "w") as f:
- f.write(editor.value)
- def change_font():
- editor.font = font.value
- def change_color():
- editor.text_color = color.value
- def change_bg_color():
- editor.bg = bg_color.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")
- # 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")
- # 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", align="right", command=save_file)
- # create an open button which uses the open_file function
- open_button = PushButton(file_controls, text="Open", align="right", command=open_file)
- # 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", scrollbar=True)
- editor.text_color="Green"
- editor.bg="Purple"
- preferences_controls = Box(app, align="bottom", width="fill", border=True)
- preference_labels = Box(app, align="bottom", width="fill", border=True)
- font = Combo(preferences_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font)
- color = Combo(preferences_controls, options=["Yellow", "Green", "Blue", "Orange", "Pink", "Purple", "Red", "Cyan", "Black", "White"], selected="Green", align="left", command=change_color)
- bg_color = Combo(preferences_controls, options=["Yellow", "Green", "Blue", "Orange", "Pink", "Purple", "Red", "Cyan", "Black", "White"], selected="Purple", align="left", command=change_bg_color)
- size = Slider(preferences_controls, align="left", command=change_text_size, start=10, end=18)
- text_font = Text(preference_labels,text="Font Text Color Bg Color FontSize", align="left")
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement