xavicano

Untitled

Aug 18th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.50 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo
  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. # function for change size font
  17. def font_button():
  18.     editor.font=font_combo.value
  19.        
  20. # function for change align DOES NOT WORK
  21. def align_button():
  22.     editor.align=align_combo.value
  23.    
  24. # function for change color  
  25. def color_button():
  26.     editor.text_color=color_combo.value
  27.     if color_combo.value=="red":
  28.         size_combo.disable()
  29.        
  30.  
  31.  
  32.    
  33. # function for change font
  34. def size_button():
  35.     editor.text_size=size_combo.value  
  36.     editor.resize(1, 1)
  37.     editor.resize("fill", "fill")    
  38.  
  39. def enable_save():
  40.     save_button.show()
  41.  
  42.  
  43. app = App(title="texteditor")
  44.  
  45. # create a box to house the controls, we want the box to span the entire width of the app
  46. file_controls = Box(app, align="top", width="fill")
  47. format_controls=Box(app, align="top", width="fill")
  48.  
  49. # create a TextBox for the file name
  50. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  51.  
  52. # create a save button which uses the save_file function
  53. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  54.  
  55. # create an open button which uses the open_file function
  56. open_button = PushButton(file_controls, text="Open", command=open_file,  align="right")
  57.  
  58. # create an open button which uses the open_file function
  59. color_combo = Combo(format_controls, options=["red","green","blue","cyan","black"], selected="black", align="right", command=color_button)
  60.  
  61. # create an open button which uses the open_file function
  62. font_combo = Combo(format_controls, options=["Arial", "Helevetica","Courier"], selected="Courier", align="right", command=font_button)
  63.  
  64. # create an open button which uses the open_file function
  65. size_combo = Combo(format_controls, options=[6,8,10,12,14,16,18,20], selected="10", align="right", command=size_button)
  66.  
  67. # create an open button which uses the open_file function
  68. align_combo = Combo(format_controls, options=["left","right","top","bottom"], width=40,selected="left", align="right", command=align_button)
  69.  
  70. # create a TextBox which is not in the box and fills the rest of the GUI
  71. editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
  72.  
  73. app.display()
Advertisement
Add Comment
Please, Sign In to add comment