Advertisement
bensimmo

Untitled

Feb 8th, 2021
1,215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.58 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo, Slider, MenuBar
  2.  
  3. # function for reading files
  4. def open_file():
  5.      # Use filedialog introduced in guizero 1.1.0, may need to alter check to None if bug is fixed
  6.     file_name_open = app.select_file(title="Select file", folder=".", filetypes=[["All files", "*.*"]], save=False)
  7.     if file_name_open is not "":
  8.         with open(file_name_open, "r") as f:
  9.             editor.value = f.read()
  10.             file_name.value = file_name_open
  11.            
  12. # function for writing files
  13. def save_file():
  14.     # Use filedialog introduced in guizero 1.1.0, may need to alter check to None if bug is fixed
  15.     file_name_save = app.select_file(title="Select file", folder=".", filetypes=[["All files", "*.*"]], save=True)
  16.     if file_name_save is not "":
  17.         with open(file_name_save, "w") as f:
  18.             f.write(editor.value)
  19.             save_button.disable()
  20.             file_name.value = file_name_save
  21.  
  22. def enable_save():
  23.     save_button.enable()
  24.        
  25. def change_font():
  26.     editor.font = font.value
  27.     colour.font = font.value
  28.     font.font = font.value
  29.  
  30. def change_text_size():
  31.     editor.text_size = size.value
  32.      # 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
  33.     editor.resize(1, 1)
  34.     editor.resize("fill", "fill")
  35.    
  36. def change_text_colour():
  37.     editor.text_color = colour.value
  38.     font.text_color = colour.value
  39.     colour.text_color = colour.value
  40.    
  41. def edit_cut():
  42.     pass
  43. def edit_copy():
  44.     pass
  45. def edit_paste():
  46.     pass
  47. def edit_selectall():
  48.     pass
  49.  
  50. def tools_settings():
  51.     pass
  52. def tools_help():
  53.     app.info("help", "you will find help at www.MyNotepad.not.com")
  54. def tools_about():
  55.     app.info("about","v 0.000001 \n created by : me \n year : 2021")
  56.  
  57.  
  58.  # A new function that closes the app
  59. def exit_app():
  60.     app.destroy()
  61.    
  62. app = App(title="My simple notepad")
  63.  
  64. # The new MenuBar
  65. menubar = MenuBar(app,
  66.                   toplevel=["File", "Edit", "Tools"],
  67.                   options=[
  68.                       [ ["open", open_file], ["save", save_file], ["exit", exit_app] ],
  69.                       [ ["cut", edit_cut], ["copy", edit_copy], ["paste", edit_paste], ["select all", edit_selectall] ],
  70.                       [ ["settings", tools_settings], ["help", tools_help], ["about", tools_about] ]
  71.                           ])
  72.  
  73.  # create a box to house the controls, we want the box to span the entire width of the app
  74. file_controls = Box(app, align="top", width="fill")
  75. preferences_controls = Box(app, align="top", width="fill", border=True)
  76. file_controls2 = Box(app, align="bottom", width="fill")
  77.  
  78.  
  79. # File name and open
  80. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  81. open_button = PushButton(file_controls, text="Open",  align="right", command = open_file)
  82.  
  83. # font choice
  84. font = Combo(preferences_controls, options=["ariel", "courier", "times new roman", "verdana"], align="left", command=change_font)
  85. colour = Combo(preferences_controls, options=["black", "gray", "light gray", "white", "red", "green", "blue"], align="left", command = change_text_colour)
  86. size = Slider(preferences_controls,  align="left", command=change_text_size, start=10, end=18)
  87.  
  88.  
  89.  
  90. # TheTextBox, which is not in the box and fills the rest of the GUI
  91. editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
  92.  
  93. # Save
  94. save_button = PushButton(file_controls2, text="Save",  align="right", command = save_file)
  95.  
  96. app.display()
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement