Advertisement
zhongnaomi

text editor menu 1

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