Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. from guizero import App, Text, TextBox, PushButton, Box, Combo, CheckBox, Slider, MenuBar , Window
  2.  
  3. def open_file():
  4. with open(file_name.value, "r") as f:
  5. editor.value = f.read()
  6. app.info("info", "File Opened")
  7. save_button.disable()
  8.  
  9. def save_file():
  10. with open(file_name.value, "w") as f:
  11. f.write(editor.value)
  12. app.info("info", "File Saved")
  13. save_button.disable()
  14. open_button.enable()
  15.  
  16.  
  17. def enable_save():
  18. open_button.disable() # changes in text - "Open Button" disabled to not lose changes
  19. save_button.enable()
  20.  
  21. def change_font():
  22. editor.font = font.value
  23.  
  24. def change_text_size():
  25. editor.text_size = size.value
  26. editor.resize(1, 1)
  27. editor.resize("fill", "fill")
  28.  
  29. def change_text_color():
  30. editor.text_color = font_color.value
  31.  
  32. def change_background_color():
  33. editor.bg = background_color.value
  34.  
  35. # A new functions that changes appearance or closes the app
  36. def big_window():
  37. app.width = 1200
  38. app.height = 800
  39. app.text_size = 16
  40. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  41.  
  42. def small_window():
  43. app.width = 600
  44. app.height = 400
  45. app.text_size = 8
  46. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  47.  
  48. def dark_theme():
  49. app.bg = "black"
  50. app.text_color = "white"
  51.  
  52. def close_editor():
  53. app.destroy()
  54.  
  55.  
  56. def exit_app():
  57. def close_warn_window():
  58. warn_window.destroy()
  59. if save_button.enabled == True:
  60. warn_window = Window(app,title="File not saved", bg="red", height =40)
  61. save_button2 = PushButton(warn_window, text="Save", command=save_file, align="right")
  62. exit_button = PushButton(warn_window, text="Exit without Save", command=close_editor, align="right")
  63. close_warn_window = PushButton(warn_window, text="Close It", command=close_warn_window, align="left")
  64. if save_button.enabled == False:
  65. close_editor()
  66.  
  67. app = App(title="GuiZeroTextEditor_v5" , width=900, height=700)
  68.  
  69. # The new MenuBar
  70. menubar = MenuBar(app,
  71. toplevel=["File" ,"Editor appearance" ],
  72. options=[
  73. [ ["open",open_file], ["save",save_file],["exit",exit_app] ],
  74. [ ["Big window",big_window], ["Small window",small_window], ["Dark theme", dark_theme] ]
  75. ])
  76.  
  77. file_controls = Box(app, align="top", width="fill", border=True)
  78. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  79. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  80. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  81.  
  82.  
  83. editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
  84.  
  85. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  86. font_name = Text(preferences_controls, text="Font:" , align ="left")
  87. font = Combo(preferences_controls, options=["Courier", "Times New Roman", "Verdana", "Piboto Condensed"], align="left", command=change_font)
  88. font_color_text = Text(preferences_controls, text="Font color:" , align ="left")
  89. font_color = Combo(preferences_controls, options=["black", "red", "green" , "blue" , "yellow"], align="left", command=change_text_color)
  90. background_color_text = Text(preferences_controls, text="Background color:" , align ="left")
  91. background_color = Combo(preferences_controls, options=["white", "black"], align="left", command=change_background_color)
  92. size = Slider(preferences_controls, align="left", start = 10, end = 42, command=change_text_size)
  93.  
  94. save_button.disable() #nothing in editor - no save possibility
  95. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement