istvanrefle

Untitled

Dec 29th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo
  2.  
  3. app = App(title="texteditor")
  4.  
  5. # function for reading files
  6. def open_file():
  7. with open(file_name.value, "r") as f:
  8. editor.value = f.read()
  9.  
  10. # function for writing files
  11. def save_file():
  12. with open(file_name.value, "w") as f:
  13. f.write(editor.value)
  14.  
  15. def change_font_type():
  16. editor.font = cmb_font_type.value
  17.  
  18. def change_font_size():
  19. editor.text_size = cmb_font_size.value
  20.  
  21. def change_font_color():
  22. editor.text_color = cmb_font_color.value
  23.  
  24. box_ribbon = Box(app, align="top", width="fill")
  25.  
  26.  
  27. # create a box to house the controls, we want the box to span the entire width of the app
  28. box_file_controls = Box(box_ribbon, align="top", width="fill")
  29.  
  30. # create an open button which uses the open_file function
  31. open_button = PushButton(box_file_controls, text="Open", align="left", command=open_file)
  32.  
  33. # create a save button which uses the save_file function
  34. save_button = PushButton(box_file_controls, text="Save", align="left", command=save_file)
  35.  
  36. # create a TextBox for the file name
  37. file_name = TextBox(box_file_controls, text="text_file.txt", width=50, align="right")
  38.  
  39. box_font_controls = Box(box_ribbon, align="top", width="fill")
  40.  
  41. cmb_font_type = Combo (box_font_controls, options=["courier", "helvetica", "times new roman"], align="left", command=change_font_type, width = 16)
  42. cmb_font_size = Combo (box_font_controls, options=["8", "12", "16", "24"], align="left", command=change_font_size, width = 4)
  43. cmb_font_color = Combo (box_font_controls, options=["black", "red", "blue", "green"], align="left", command=change_font_color, width = 8)
  44.  
  45.  
  46. # create a TextBox which is not in the box and fills the rest of the GUI
  47. editor = TextBox(app, multiline=True, height="fill", width="fill")
  48.  
  49. app.display()
Advertisement
Add Comment
Please, Sign In to add comment