Advertisement
johnrtate

Untitled

Feb 19th, 2020
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, info, Combo,Slider
  2. from guizero import CheckBox
  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. # function for writing files
  11. def save_file():
  12.     with open(file_name.value, "w") as f:
  13.         f.write(editor.value)
  14.     info(title="File Save",text="File " + file_name.value + " Saved")     # confirm file saved
  15.  
  16. def change_font():
  17.     editor.font = font.value
  18.  
  19. def change_text_size():
  20.     editor.text_size = size.value
  21.     editor.resize(1, 1)
  22.     editor.resize("fill", "fill")
  23. def change_text_colour():
  24.     editor.text_color = colour.value
  25.  
  26. # create a box to house the controls, we want the box to span the entire width of the app
  27. file_controls = Box(app, align="top", width="fill")
  28.  
  29. # create a TextBox for the file name
  30. file_name = TextBox(file_controls, text="text_file.txt", width=35, align="left")
  31. file_name.font = "Times New Roman"
  32. file_name.text_color = 'green'
  33. file_name.text_size = 14
  34. file_name.bg="white"
  35.  
  36. # create a save button which uses the save_file function
  37. save_button = PushButton(file_controls, text="Save",  align="right",command=save_file)
  38. # create an open button which uses the open_file function
  39. open_button = PushButton(file_controls, text="Open",  align="right", command=open_file)
  40. # create a TextBox which is not in the box and fills the rest of the GUI
  41. editor = TextBox(app, multiline=True, height="fill", width="fill")
  42.  
  43. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  44. preferences_controls.bg=(150,150,150)
  45. font = Combo(preferences_controls, options=["courier", "helvecia", "verdana"], align="left", command=change_font)
  46. size = Slider(preferences_controls,  align="right", start = 10, end = 40, command=change_text_size)
  47. colour = Combo(preferences_controls, options=["black", "red", "blue","green","orange"], align="right",command=change_text_colour)
  48.  
  49. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement