Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box
  2.  
  3. # function for reading files
  4. def open_file():
  5. with open(file_name.value, "r") as f:
  6. editor.value = f.read()
  7.  
  8. # function for writing files
  9. def save_file():
  10. with open(file_name.value, "w") as f:
  11. f.write(editor.value)
  12.  
  13. def incfont():
  14. editor.text_size=editor.text_size+1
  15.  
  16.  
  17. def decfont():
  18. editor.text_size=editor.text_size-1
  19.  
  20. app = App(title="texteditor")
  21.  
  22. # create a box to house the controls, we want the box to span the entire width of the app
  23. file_controls = Box(app, align="top", width="fill")
  24.  
  25. # create a TextBox for the file name
  26. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left", command=open_file)
  27.  
  28. # create a save button which uses the save_file function
  29. save_button = PushButton(file_controls, text="Save", align="right", command=save_file)
  30.  
  31. # create an open button which uses the open_file function
  32. open_button = PushButton(file_controls, text="Open", align="right")
  33.  
  34. label="F"+chr(8593)
  35. #create a button that will inc the font size
  36. fontup = PushButton(file_controls, text=label,command=incfont, align="right")
  37.  
  38. label="F"+chr(8595)
  39. #create a button that will inc the font size
  40. fontdown = PushButton(file_controls, text=label,command=decfont, align="right")
  41.  
  42.  
  43.  
  44. # create a TextBox which is not in the box and fills the rest of the GUI
  45. editor = TextBox(app, multiline=True, height="fill", width="fill")
  46.  
  47. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement