Advertisement
sclnl

Untitled

Jan 18th, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.64 KB | None | 0 0
  1. from guizero import App, Text, TextBox, Box, MenuBar, Combo, Slider, info
  2.  
  3. # These are the functions that are called by selecting options from each submenu
  4.  
  5. editor_text_saved = False
  6.  
  7. def open_file():
  8.     with open(file_name.value, "r") as f:
  9.         editor.value = f.read()
  10.  
  11. def save_file():
  12.     with open(file_name.value, "w") as f:
  13.         f.write(editor.value)
  14.     editor.bg="White"
  15.    
  16. def exit_app():
  17.     if (editor.bg == "Light Grey"):
  18.         info("Warning","You must save file before exit ...")
  19.     else:
  20.         app.destroy()
  21.    
  22. def clear_text():
  23.     editor.clear()
  24.  
  25. def wonb():
  26.     if (editor.bg == "Light Grey"):
  27.         info("Warning","You must save file before doing this ...")
  28.     else:
  29.         editor.bg= "black"
  30.         editor.text_color= "white"
  31.    
  32. def bonw():
  33.     if (editor.bg == "Light Grey"):
  34.         info("Warning","You must save file before doing this ...")
  35.     else:
  36.         editor.bg= "white"
  37.         editor.text_color= "black"
  38.  
  39. # This is a text editor with menu
  40.  
  41. app = App(title="Text Editor with menu")
  42.  
  43. # The new MenuBar
  44. menubar = MenuBar(app,
  45.     toplevel=["File","Options"],
  46.     options=[[["open",open_file],["save",save_file],["exit",exit_app]],
  47.                  [["clear",clear_text],["white on black",wonb],["black on white",bonw]]])
  48.  
  49. file_controls = Box(app, align="top", width="fill")
  50. font_controls = Box(app, align="top", width="fill", )
  51.  
  52. file_label = Text(file_controls, text="File Name", width=10, align="left")
  53. file_name = TextBox(file_controls, text="Infinito.txt", width=50, align="left")
  54.  
  55. # function to select font
  56. def select_font():
  57.     editor.font= font_choice.value
  58.  
  59. # menu to select a font
  60. font_choice = Combo(font_controls, options=["Bitstream", "Courier", "eufm10", "Helvetica", "Purisa", "Times"],
  61.                     selected="Bitstream", command=select_font, width=10, align="left")
  62.  
  63. # function to select font color
  64. def select_color():
  65.     editor.text_color= font_color.value
  66.  
  67. # menu to select a font
  68. font_color = Combo(font_controls, options=["Yellow", "Blue", "Green", "Black", "Red", "Violet"],
  69.                     selected="Grey", command=select_color, width=10, align="left")
  70.  
  71. # create a Text for the font size
  72. font_size_label = Text(font_controls, text="Font Size", width=10, align="left")
  73.  
  74. # function to select font size
  75. def slider_changed(slider_value):
  76.     editor.text_size= font_size.value
  77.  
  78. font_size = Slider(font_controls, command=slider_changed, start=10, end=40, width=80, align="left")
  79.  
  80. def set_not_saved():
  81.     editor.bg="Light Grey"
  82.  
  83. editor = TextBox(app, multiline=True, scrollbar=True, height="fill", width="fill", command=set_not_saved)
  84.  
  85. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement