Advertisement
MarkO-FL

Untitled

Aug 23rd, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo, CheckBox, Slider, MenuBar, Text
  2.  
  3.  
  4. def file_function():
  5.     print("File option")
  6.  
  7. def edit_function():
  8.     print("Edit option")
  9.  
  10. def open_file():
  11.     with open(file_name.value, "r") as f:
  12.         editor.value = f.read()
  13.  
  14. def save_file():
  15.     with open(file_name.value, "w") as f:
  16.         f.write(editor.value)
  17.         save_button.disable()
  18.  
  19. def enable_save():
  20.     save_button.enable()
  21.  
  22. # A new function that closes the app
  23. def exit_app():
  24.     app.destroy()
  25.  
  26. # This is where any additional functions needed to run your script go
  27. def change_font():
  28.     editor.font = font.value
  29.        
  30. def change_text_size():
  31.     editor.text_size = size.value
  32.     editor.resize(1, 1)
  33.     editor.resize("fill", "fill")
  34.    
  35. def change_text_color():
  36.     editor.text_color = color.value
  37.  
  38. def change_theme():
  39.  
  40.     if dark_theme.value:
  41.  
  42.         app.bg = "black"
  43.  
  44.         app.text_color = "white"
  45.  
  46.     else:
  47.  
  48.         app.bg = None
  49.  
  50.         app.text_color = None
  51.  
  52. app = App(title="textzero")
  53.  
  54. # The new MenuBar
  55. menubar = MenuBar(app,
  56.                   toplevel=["File", "Edit"],
  57.                   options=[
  58.                       [ ["File option 1", file_function], ["File option 2", file_function] ],
  59.                       [ ["Edit option 1", edit_function], ["Edit option 2", edit_function] ]
  60.                   ])
  61.  
  62. file_controls = Box(app, align="top", width="fill", border=True)
  63. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  64.  
  65. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  66. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  67.  
  68. editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
  69.  
  70. # This is where your additional features go
  71.  
  72.  
  73. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  74. font = Combo(preferences_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font)
  75. size = Slider(preferences_controls,  align="left", start = 8, end = 42, command=change_text_size)
  76. color = Combo(preferences_controls, options=["red", "orange", "navy"],align="left", command=change_text_color)
  77. dark_theme = CheckBox(preferences_controls, text="dark", align="left", command=change_theme)
  78. message = Text(app, text="TextZero Control Panel - Change font, colour, text-size and theme below", size=8, bg ="yellow" )
  79.  
  80. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement