Advertisement
xavicano

Untitled

Aug 18th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 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.     editor.resize(1, 1)
  31.     editor.resize("fill", "fill")    
  32.  
  33.  
  34. app = App(title="texteditor")
  35.  
  36. # create a box to house the controls, we want the box to span the entire width of the app
  37. file_controls = Box(app, align="top", width="fill")
  38. format_controls=Box(app, align="top", width="fill")
  39.  
  40. # create a TextBox for the file name
  41. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  42.  
  43. # create a save button which uses the save_file function
  44. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  45.  
  46. # create an open button which uses the open_file function
  47. open_button = PushButton(file_controls, text="Open", command=open_file,  align="right")
  48.  
  49. # create an open button which uses the open_file function
  50. color_button = Combo(format_controls, options=["red","green","blue","cyan","black"], selected="black", align="right", command=color_button)
  51.  
  52. # create an open button which uses the open_file function
  53. font_button = Combo(format_controls, options=["Arial", "Helevetica","Courier"], selected="Courier", align="right", command=font_button)
  54.  
  55. # create an open button which uses the open_file function
  56. size_button = Combo(format_controls, options=[6,8,10,12,14,16,18,20], selected="10", align="right", command=size_button)
  57.  
  58. # create an open button which uses the open_file function
  59. align_button = Combo(format_controls, options=["left","right","top","bottom"], width=40,selected="left", align="right", command=align_button)
  60.  
  61. # create a TextBox which is not in the box and fills the rest of the GUI
  62. editor = TextBox(app, multiline=True, height="fill", width="fill")
  63.  
  64. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement