Advertisement
Mori007

texteditor&tools

Feb 9th, 2021
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. from guizero import App, TextBox, Text, PushButton, Box, Combo
  2.  
  3. app = App(title="texteditor")
  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. # functioning for saving files
  11. def save_file():
  12.     with open(file_name.value, "w") as f:
  13.         f.write(editor.value)
  14.        
  15. # create a preference new font, size and colour of the text
  16. def change_font():
  17.     editor.font = font.value
  18.    
  19. def change_text_size():
  20.     text_size = {"small": 6, "medium": 12, "large": 24}
  21.     editor.text_size = text_size[size.value]
  22.     editor.resize(1, 1)
  23.     editor.resize("fill", "fill")
  24.    
  25. def change_colour():
  26.     editor.text_color = colour.value
  27.  
  28.    
  29. # create a box to house the controls, we want the box to span the entire width of the app
  30. file_controls = Box(app, align="top", width="fill")
  31.  
  32. # create a TextBox for the file name
  33. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  34.  
  35. # create a save button which uses the save_file function
  36. save_button = PushButton(file_controls, text="Save",  command=save_file, align="right")
  37.  
  38. # create an open button which uses the open_file function
  39. open_button = PushButton(file_controls, text="Open",  command=open_file, align="right")
  40.  
  41. # create a TextBox which is not in the box and fills the rest of the GUI
  42. editor = TextBox(app, multiline=True, height="fill", width="fill", command=change_colour)
  43.  
  44. # create a box that consist controling the text
  45. preferences_control = Box(app, layout='auto', align="bottom", width="fill")
  46. font = Combo(preferences_control,options=["verdana","arial","times new roman"], align="right", command=change_font)
  47. size = Combo(preferences_control,options=["small","medium","large"], align="right", command=change_text_size)
  48. colour = Combo(preferences_control, options=["red","green","black"], align="right", command=change_colour)
  49.  
  50. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement