Advertisement
xavicano

Untitled

Aug 18th, 2019
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo
  2.  
  3.  
  4.  
  5. # function for reading files
  6. def open_file():
  7.     with open(file_name.value, "r") as f:
  8.         editor.value = f.read()
  9.  
  10. # function for writing files
  11. def save_file():
  12.     with open(file_name.value, "w") as f:
  13.         f.write(editor.value)
  14.  
  15. # function for change size font
  16. def font_button():
  17.     editor.font=font_button.value
  18.        
  19. # function for change align DOES NOT WORK
  20. def align_button():
  21.     editor.align=align_button.value
  22.    
  23. # function for change color
  24. def color_button():
  25.     editor.text_color=color_button.value    
  26.    
  27. # function for change font
  28. def size_button():
  29.     editor.text_size=size_button.value      
  30.  
  31.  
  32. app = App(title="texteditor")
  33.  
  34. # create a box to house the controls, we want the box to span the entire width of the app
  35. file_controls = Box(app, align="top", width="fill")
  36. format_controls=Box(app, align="top", width="fill")
  37.  
  38. # create a TextBox for the file name
  39. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  40.  
  41. # create a save button which uses the save_file function
  42. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  43.  
  44. # create an open button which uses the open_file function
  45. open_button = PushButton(file_controls, text="Open", command=open_file,  align="right")
  46.  
  47. # create an open button which uses the open_file function
  48. color_button = Combo(format_controls, options=["red","green","blue","cyan","black"], selected="black", align="right", command=color_button)
  49.  
  50. # create an open button which uses the open_file function
  51. font_button = Combo(format_controls, options=["Arial", "Helevetica","Courier"], selected="Courier", align="right", command=font_button)
  52.  
  53. # create an open button which uses the open_file function
  54. size_button = Combo(format_controls, options=[6,8,10,12,14,16,18,20], selected="10", align="right", command=size_button)
  55.  
  56. # create an open button which uses the open_file function
  57. align_button = Combo(format_controls, options=["left","right","top","bottom"], width=40,selected="left", align="right", command=align_button)
  58.  
  59. # create a TextBox which is not in the box and fills the rest of the GUI
  60. editor = TextBox(app, multiline=True, height="fill", width="fill")
  61.  
  62. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement