Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, PushButton, Box, Combo, Slider
- app = App(title="Colin File Editor")
- # function for reading files
- def open_file():
- with open(file_name.value , "r" ) as f:
- editor.value = f.read()
- # function for saving files
- def save_file():
- with open(file_name.value, "w") as f:
- f.write(editor.value)
- # Disable the save_button
- # save_button.disable()
- save_button.hide() # temp change
- def enable_save():
- save_button.enable()
- def show_save():
- save_button.show()
- # change font function
- 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_colour():
- editor.text_color = colur.value
- # create a TextBox which is not in the bottom box and fills the rest of the GUI
- editor = TextBox(app, multiline=True, height="fill", width="fill", command=show_save)
- # create a 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")
- #create some padding for the filename box
- pad = Box(file_controls, align="left", width=8, height= 1)
- # 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",visible= False) #enabled=False)
- # create an open button which uses the open_file function
- open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
- #create a place for text preferences called pref controls
- pref_controls = Box(app, align="bottom", width="fill", border=True)
- #create some padding for the pref_controls box
- pad2 = Box(pref_controls, align="left", width=8, height= 1)
- #create the Combo for Font Selection
- font = Combo(pref_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font,)
- #Font Size Changer
- size = Slider(pref_controls, align="left", command=change_text_size, start=10, end=18)
- #Font Colour Changer
- colur = Combo(pref_controls, options=["green", "red", "blue", "black"],align="left", command=change_colour)
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement