Advertisement
bensimmo

Untitled

Feb 4th, 2021
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo, Slider
  2.  
  3. # function for reading files
  4. def open_file():
  5.     with open(file_name.value, "r") as f:
  6.         editor.value = f.read()
  7.  
  8. # function for writing files
  9. def save_file():
  10.     with open(file_name.value, "w") as f:
  11.         f.write(editor.value)
  12.        
  13. def change_font():
  14.     editor.font = font.value
  15.  
  16. def change_text_size():
  17.     editor.text_size = size.value
  18.     # resize the widget because if the text is made bigger, this might affect the size of the TextBox so guizero needs to know how to maintain the intended layout
  19.     editor.resize(1, 1)
  20.     editor.resize("fill", "fill")
  21.    
  22. def change_text_colour():
  23.     editor.text_color = colour.value
  24.    
  25. app = App(title="My simple notepad")
  26.  
  27. # create a box to house the controls, we want the box to span the entire width of the app
  28. file_controls = Box(app, align="top", width="fill")
  29. preferences_controls = Box(app, align="top", width="fill", border=True)
  30. file_controls2 = Box(app, align="bottom", width="fill")
  31.  
  32.  
  33. # File name and open
  34. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  35. open_button = PushButton(file_controls, text="Open",  align="right", command = open_file)
  36.  
  37. # font choice
  38. font = Combo(preferences_controls, options=["ariel", "courier", "times new roman", "verdana"], align="left", command=change_font)
  39. colour = Combo(preferences_controls, options=["black", "gray", "light gray", "white", "red", "green", "blue"], align="left", command = change_text_colour)
  40. size = Slider(preferences_controls,  align="left", command=change_text_size, start=10, end=18)
  41.  
  42.  
  43.  
  44. # TheTextBox, which is not in the box and fills the rest of the GUI
  45. editor = TextBox(app, multiline=True, height="fill", width="fill")
  46.  
  47. # Save
  48. save_button = PushButton(file_controls2, text="Save",  align="right", command = save_file)
  49.  
  50. app.display()
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement