Advertisement
johnrtate

Untitled

Feb 19th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 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.      # Disable the save_button
  16.     save_button.hide()
  17. def change_font():
  18.     editor.font = font.value
  19.  
  20. def change_text_size():
  21.     editor.text_size = size.value
  22.     editor.resize(1, 1)
  23.     editor.resize("fill", "fill")
  24. def change_text_colour():
  25.     editor.text_color = colour.value
  26. def enable_save():
  27.     save_button.show()
  28. def open_status():  #if no filename open button disabled
  29.     if len(file_name.value)==0:
  30.         open_button.disable()
  31.     else:
  32.          open_button.enable()
  33. # create a box to house the controls, we want the box to span the entire width of the app
  34. file_controls = Box(app, align="top", width="fill")
  35.  
  36. # create a TextBox for the file name
  37. file_name = TextBox(file_controls, text="text_file.txt", command=open_status,width=35, align="left")
  38. file_name.font = "Times New Roman"
  39. file_name.text_color = 'green'
  40. file_name.text_size = 14
  41. file_name.bg="white"
  42.  
  43. # create a save button which uses the save_file function
  44. save_button = PushButton(file_controls, text="Save",  align="right",command=save_file)
  45. save_button.hide()
  46.  
  47. # create an open button which uses the open_file function
  48. open_button = PushButton(file_controls, text="Open",  align="right", command=open_file)
  49.    
  50. # create a TextBox which is not in the box and fills the rest of the GUI
  51. editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
  52.  
  53. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  54. preferences_controls.bg=(150,150,150)
  55. font = Combo(preferences_controls, options=["courier", "helvecia", "verdana"], align="left", command=change_font)
  56. size = Slider(preferences_controls,  align="right", start = 10, end = 40, command=change_text_size)
  57. colour = Combo(preferences_controls, options=["black", "red", "blue","green","orange"], align="right",command=change_text_colour)
  58.  
  59. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement