Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. ### Replace the original import line with this:
  2. from guizero import App, Text, TextBox, PushButton, Box, Combo, CheckBox, Slider
  3.  
  4. app = App(title="texteditor")
  5.  
  6. # function for reading files
  7. def open_file():
  8. with open(file_name.value, "r") as f:
  9. editor.value = f.read()
  10.  
  11. # function for writing files
  12. def save_file():
  13. with open(file_name.value, "w") as f:
  14. f.write(editor.value)
  15.  
  16. def change_font():
  17. editor.font = font.value
  18.  
  19. def change_color():
  20. editor.text_color = color.value
  21.  
  22. def change_bg_color():
  23. editor.bg = bg_color.value
  24.  
  25. def change_text_size():
  26. editor.text_size = size.value
  27. # 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
  28. editor.resize(1, 1)
  29. editor.resize("fill", "fill")
  30.  
  31. # create a box to house the controls, we want the box to span the entire width of the app
  32. file_controls = Box(app, align="top", width="fill")
  33.  
  34. # create a TextBox for the file name
  35. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  36.  
  37. # create a save button which uses the save_file function
  38. save_button = PushButton(file_controls, text="Save", align="right", command=save_file)
  39.  
  40. # create an open button which uses the open_file function
  41. open_button = PushButton(file_controls, text="Open", align="right", command=open_file)
  42.  
  43. # create a TextBox which is not in the box and fills the rest of the GUI
  44. editor = TextBox(app, multiline=True, height="fill", width="fill", scrollbar=True)
  45. editor.text_color="Green"
  46. editor.bg="Purple"
  47. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  48. preference_labels = Box(app, align="bottom", width="fill", border=True)
  49. font = Combo(preferences_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font)
  50. color = Combo(preferences_controls, options=["Yellow", "Green", "Blue", "Orange", "Pink", "Purple", "Red", "Cyan", "Black", "White"], selected="Green", align="left", command=change_color)
  51. bg_color = Combo(preferences_controls, options=["Yellow", "Green", "Blue", "Orange", "Pink", "Purple", "Red", "Cyan", "Black", "White"], selected="Purple", align="left", command=change_bg_color)
  52. size = Slider(preferences_controls, align="left", command=change_text_size, start=10, end=18)
  53. text_font = Text(preference_labels,text="Font Text Color Bg Color FontSize", align="left")
  54. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement