Advertisement
aidanpl

GUI_programming_2_8_Text_Editor_0.2.py

Feb 17th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo, CheckBox, Slider
  2.  
  3. def open_file():
  4.     with open(file_name.value, "r") as f:
  5.         editor.value = f.read()
  6.  
  7. def save_file():
  8.     with open(file_name.value, "w") as f:
  9.         f.write(editor.value)
  10.  
  11. def change_font():
  12.     editor.font = font.value
  13.  
  14. def change_text_size():
  15.     editor.text_size = size.value
  16.     editor.resize(1, 1)
  17.     editor.resize("fill", "fill")
  18.  
  19. def change_colour():
  20.     editor.text_color = colour.value
  21.  
  22.  
  23. app = App(title="textzero")
  24.  
  25. file_controls = Box(app, align="top", width="fill", border=True)
  26. file_name = TextBox(file_controls, text="hello_world.txt", width=50, align="left")
  27. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  28. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  29.  
  30.  
  31. preferences_controls = Box(app, align="left", border=True, layout="auto")
  32. font = Combo(preferences_controls, options=["courier", "times new roman", "verdana"], command=change_font)
  33. colour = Combo(preferences_controls, options=["black","red", "blue", "green"], command=change_colour)
  34. size = Slider(preferences_controls, align="left", start = 8, end = 42, command=change_text_size)
  35.  
  36. editor = TextBox(app, multiline=True, height="fill", width="fill")
  37.  
  38.  
  39. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement