Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, PushButton, Box
- # 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 incfont():
- editor.text_size=editor.text_size+1
- def decfont():
- editor.text_size=editor.text_size-1
- app = App(title="texteditor")
- # 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", command=open_file)
- # 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")
- label="F"+chr(8593)
- #create a button that will inc the font size
- fontup = PushButton(file_controls, text=label,command=incfont, align="right")
- label="F"+chr(8595)
- #create a button that will inc the font size
- fontdown = PushButton(file_controls, text=label,command=decfont, align="right")
- # 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")
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement