Advertisement
xavicano

Untitled

Aug 18th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.91 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo, MenuBar
  2.  
  3.  
  4. # function for reading files
  5. def open_file():
  6.     with open(file_name.value, "r") as f:
  7.         editor.value = f.read()
  8.  
  9. # function for writing files
  10. def save_file():
  11.     with open(file_name.value, "w") as f:
  12.         f.write(editor.value)
  13.         # Disable the save_button
  14.     save_button.hide()
  15.    
  16. # A new function that closes the app
  17. def exit_app():
  18.     app.destroy()
  19.  
  20. # function for change size font
  21. def font_button():
  22.     editor.font=font_combo.value
  23.        
  24. # function for change align DOES NOT WORK
  25. def align_button():
  26.     editor.align=align_combo.value
  27.    
  28. # function for change color  
  29. def color_button():
  30.     editor.text_color=color_combo.value
  31.     #if color_combo.value=="red":
  32.         #size_combo.disable()
  33.     #else:
  34.         #size_combo.enable()   
  35.  
  36.    
  37. # function for change font
  38. def size_button():
  39.     editor.text_size=size_combo.value  
  40.     editor.resize(1, 1)
  41.     editor.resize("fill", "fill")    
  42.  
  43. def enable_save():
  44.     save_button.show()
  45.  
  46.  
  47. app = App(title="texteditor")
  48.  
  49.  
  50. # The new MenuBar
  51. menubar = MenuBar(app,
  52.                   toplevel=["File","Edit"],
  53.                   options=[
  54.                     [["open",open_file],["save",save_file],["exit",exit_app]],
  55.                     [["Font",font_button],["Size",size_button],["Align",align_button],["Color",color_button], ]
  56.                     ])
  57.  
  58.  
  59. # create a box to house the controls, we want the box to span the entire width of the app
  60. file_controls = Box(app, align="top", width="fill", border=True)
  61. format_controls=Box(app, align="top", width="fill")
  62.  
  63. # create a TextBox for the file name
  64. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  65.  
  66. # create a save button which uses the save_file function
  67. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  68.  
  69. # create an open button which uses the open_file function
  70. open_button = PushButton(file_controls, text="Open", command=open_file,  align="right")
  71.  
  72. # create an open button which uses the open_file function
  73. color_combo = Combo(format_controls, options=["red","green","blue","cyan","black"], selected="black", align="right", command=color_button)
  74.  
  75. # create an open button which uses the open_file function
  76. font_combo = Combo(format_controls, options=["Arial", "Helevetica","Courier"], selected="Courier", align="right", command=font_button)
  77.  
  78. # create an open button which uses the open_file function
  79. size_combo = Combo(format_controls, options=[6,8,10,12,14,16,18,20], selected="10", align="right", command=size_button)
  80.  
  81. # create an open button which uses the open_file function
  82. align_combo = Combo(format_controls, options=["left","right","top","bottom"], width=40,selected="left", align="right", command=align_button)
  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. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement