Advertisement
timber101

ColinsEditorMk2

Aug 7th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.24 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo, Slider
  2.  
  3. app = App(title="Colin File Editor")
  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 saving files
  11. def save_file():
  12.     with open(file_name.value, "w") as f:
  13.         f.write(editor.value)
  14.        
  15. # change font function
  16. def change_font():
  17.     editor.font = font.value
  18.    
  19. def change_text_size():
  20.     editor.text_size = size.value
  21.     # 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
  22.     editor.resize(1, 1)
  23.     editor.resize("fill", "fill")
  24.    
  25. def change_colour():
  26.     editor.text_color = colur.value
  27.  
  28.  
  29. # create a TextBox which is not in the bottom box and fills the rest of the GUI
  30. editor = TextBox(app, multiline=True, height="fill", width="fill")
  31.  
  32. # create a box to house the controls, we want the box to span the entire width of the app
  33. file_controls = Box(app, align="bottom", width="fill")
  34.  
  35. #create some padding for the filename box
  36. pad = Box(file_controls, align="left", width=8, height= 1)
  37.  
  38. # create a TextBox for the file name
  39. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  40.  
  41. # create a save button which uses the save_file function
  42. save_button = PushButton(file_controls, text="Save", command=save_file , align="right")
  43.  
  44. # create an open button which uses the open_file function
  45. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  46.  
  47.  
  48. #create a place for text preferences called pref controls
  49. pref_controls = Box(app, align="bottom", width="fill", border=True)
  50.  
  51. #create some padding for the pref_controls box
  52. pad2 = Box(pref_controls, align="left", width=8, height= 1)
  53.  
  54. #create the Combo for Font Selection
  55. font = Combo(pref_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font,)
  56.  
  57. #Font Size Changer
  58. size = Slider(pref_controls,  align="left", command=change_text_size, start=10, end=18)
  59.  
  60. #Font Colour Changer
  61. colur = Combo(pref_controls, options=["green", "red", "blue", "black"],align="left", command=change_colour)
  62.  
  63. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement