Advertisement
jolgri

Assignment 11 Menu bar

Jan 5th, 2020
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #Don't forget to add Menubar to list of imports
  2. from guizero import App, TextBox, PushButton, Box, Combo, CheckBox, Slider, MenuBar
  3.  
  4. def open_file():
  5. with open(file_name.value, "r") as f:
  6. editor.value = f.read()
  7.  
  8. def edit_file():
  9. with open(file_name.value, "r") as f:
  10. editor.bg = "yellow"
  11.  
  12. def save_file():
  13. with open(file_name.value, "w") as f:
  14. f.write(editor.value)
  15. save_button.disable()
  16.  
  17. def enable_save():
  18. save_button.enable()
  19.  
  20. # A new function that closes the app
  21. def exit_app():
  22. app.destroy()
  23.  
  24. # This is where any additional functions needed to run your script go
  25.  
  26. app = App(title="textzero")
  27.  
  28. # The new MenuBar
  29. menubar = MenuBar(app,
  30. toplevel=["File"],
  31. options=[[["open",open_file], ["edit",edit_file],["save",save_file],["exit",exit_app]]])
  32.  
  33. file_controls = Box(app, align="top", width="fill", border=True)
  34. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  35.  
  36. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  37. edit_button = PushButton(file_controls, text="Lightyellow", command=edit_file, align="right")
  38. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  39.  
  40. editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
  41.  
  42. # This is where your additional features go
  43.  
  44. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement