Advertisement
mrFitzpatrick

textEditor_V1

Aug 19th, 2019
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.53 KB | None | 0 0
  1. from guizero import App, TextBox, Text, PushButton, Box, Combo
  2.  
  3. # function for reading files
  4. def open_file():
  5.     with open(file_name.value, "r") as f:
  6.         editor.value = f.read()
  7.         app.title = "Now editing " + file_name.value
  8.  
  9. # function for writing files
  10. def save_file():
  11.     with open(file_name.value, "w") as f:
  12.         f.write(editor.value)
  13.         app.title = file_name.value + " successfully saved!"
  14.        
  15. def bg_col():
  16.     if cmb_bg.value == "Calm":
  17.         editor.bg = "#fcdd88"
  18.         editor.text_color = "#855600"
  19.     elif cmb_bg.value == "Clear":
  20.         editor.bg = "#ffffff"
  21.         editor.text_color = "#2222ff"
  22.     elif cmb_bg.value == "Hacker":
  23.         editor.bg = "#000000"
  24.         editor.text_color = "#4cf000"
  25.  
  26. def font_up():
  27.     editor.text_size = editor.text_size + 2
  28.  
  29. def font_down():
  30.     editor.text_size = editor.text_size - 2
  31.  
  32. app = App(title="texteditor")
  33.  
  34. #Box to house the visual options
  35. box_appearance_controls = Box(app, layout="auto", align="top", width="fill", height=50)
  36.  
  37. #Widgets for background colour
  38. lbl_background = Text(box_appearance_controls, text="What's your mood?", align="left")
  39. cmb_bg = Combo(box_appearance_controls, options=["Clear", "Hacker", "Calm"], align="left", height="fill", command=bg_col)
  40.  
  41. #Widgets for font size
  42. lbl_size = Text(box_appearance_controls, text="        Font size: ", align="left")
  43. box_spacer = Box(box_appearance_controls, width=25, align="left", height="fill")
  44. btn_font_up = PushButton(box_appearance_controls, command=font_up, text="+", align="left")
  45. box_spacer = Box(box_appearance_controls, width=25, align="left", height="fill")
  46. btn_font_down = PushButton(box_appearance_controls, command=font_down, text="-", align="left")
  47.  
  48.  
  49. # create a TextBox which is not in the box and fills the rest of the GUI
  50. editor = TextBox(app, multiline=True, height="fill", width="fill", scrollbar=True)
  51.  
  52.  
  53. # create a box to house the controls, we want the box to span the entire width
  54. file_controls = Box(app, align="bottom", width="fill")
  55.  
  56. # create a TextBox for the file name
  57. file_name = TextBox(file_controls, text="type file name here (add .txt to the end)", width=50, align="left")
  58.  
  59. # create an open button which uses the open_file function
  60. open_button = PushButton(file_controls, text="Open",  align="right", command=open_file)
  61.  
  62. box_spacer = Box(file_controls, width=15, align="right")
  63.  
  64. # create a save button which uses the save_file function
  65. save_button = PushButton(file_controls, text="Save",  align="right", command=save_file)
  66.  
  67.  
  68.  
  69. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement