istvanrefle

Untitled

Dec 29th, 2019
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo, Slider, info, MenuBar
  2.  
  3. app = App(title="texteditor")
  4.  
  5. #def main():
  6. # disable_save()
  7.  
  8. # function for reading files
  9. def open_file():
  10. with open(file_name.value, "r") as f:
  11. editor.value = f.read()
  12.  
  13. # function for writing files
  14. def save_file():
  15. # button_save.visible = False
  16. with open(file_name.value, "w") as f:
  17. f.write(editor.value)
  18. button_save.disable()
  19. # info("Hide Button","Save button is hided!")
  20. # button_save.visible = True
  21.  
  22. def enable_save():
  23. button_save.enable()
  24.  
  25. def disable_save():
  26. button_save.disable()
  27.  
  28. def exit_app():
  29. app.destroy()
  30.  
  31. def change_font_type():
  32. editor.font = cmb_font_type.value
  33. enable_save()
  34.  
  35. def change_font_size():
  36. # editor.text_size = cmb_font_size.value
  37. editor.text_size = slider_font_size.value
  38. # 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
  39. editor.resize(1, 1)
  40. editor.resize("fill", "fill")
  41. enable_save()
  42.  
  43. def change_font_color():
  44. editor.text_color = cmb_font_color.value
  45. enable_save()
  46.  
  47. def func_help():
  48. info ("TextZero Help", "This is your HELP! :)")
  49.  
  50. def func_about():
  51. info ("TextZero", "Made by us!")
  52.  
  53. # The new MenuBar
  54. menubar = MenuBar(app,
  55. toplevel=["File", "Help"],
  56. options=[
  57. [["Open",open_file],["Save",save_file],["Exit",exit_app]],
  58. [["Help", func_help], ["About", func_about]]
  59. ])
  60.  
  61.  
  62. box_ribbon = Box(app, align="top", width="fill")
  63.  
  64. # create a box to house the controls, we want the box to span the entire width of the app
  65. box_file_controls = Box(box_ribbon, align="top", width="fill")
  66.  
  67. # create an open button which uses the open_file function
  68. button_open = PushButton(box_file_controls, text="Open", align="left", command=open_file)
  69.  
  70. # create a save button which uses the save_file function
  71. button_save = PushButton(box_file_controls, text="Save", align="left", enabled = False, command=save_file)
  72.  
  73. # create a TextBox for the file name
  74. file_name = TextBox(box_file_controls, text="text_file.txt", width=50, align="right")
  75.  
  76. box_font_controls = Box(box_ribbon, align="top", width="fill")
  77.  
  78. cmb_font_type = Combo (box_font_controls, options=["courier", "helvetica", "times new roman"], align="left", command=change_font_type, width = 16)
  79. cmb_font_color = Combo (box_font_controls, options=["black", "red", "blue", "green"], align="left", command=change_font_color, width = 8)
  80. slider_font_size = Slider(box_font_controls, align="left", start = 8, end = 42, command=change_font_size)
  81. # cmb_font_size = Combo (box_font_controls, options=["8", "12", "16", "24"], align="left", command=change_font_size, width = 4)
  82.  
  83.  
  84. # create a TextBox which is not in the box and fills the rest of the GUI
  85. editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
  86.  
  87. # main()
  88.  
  89.  
  90. app.display()
Advertisement
Add Comment
Please, Sign In to add comment