Advertisement
timber101

HeroNameCreatorMk2WithSaveHidden

Aug 8th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.48 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo, Slider
  2.  
  3. app = App(title="Colin File Editor")
  4.  
  5.  
  6. # function for reading files
  7. def open_file():
  8.     with open(file_name.value , "r" ) as f:
  9.         editor.value = f.read()
  10.        
  11. # function for saving files
  12. def save_file():
  13.     with open(file_name.value, "w") as f:
  14.         f.write(editor.value)
  15.     # Disable the save_button
  16.     # save_button.disable()  
  17.     save_button.hide() # temp change
  18.    
  19. def enable_save():
  20.     save_button.enable()
  21.    
  22. def show_save():
  23.     save_button.show()
  24.  
  25.    
  26. # change font function
  27. def change_font():
  28.     editor.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_colour():
  37.     editor.text_color = colur.value
  38.  
  39.  
  40. # create a TextBox which is not in the bottom box and fills the rest of the GUI
  41. editor = TextBox(app, multiline=True, height="fill", width="fill", command=show_save)
  42.  
  43. # create a box to house the controls, we want the box to span the entire width of the app
  44. file_controls = Box(app, align="bottom", width="fill")
  45.  
  46. #create some padding for the filename box
  47. pad = Box(file_controls, align="left", width=8, height= 1)
  48.  
  49. # create a TextBox for the file name
  50. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  51.  
  52. # create a save button which uses the save_file function
  53. save_button = PushButton(file_controls, text="Save", command=save_file , align="right",visible= False) #enabled=False)
  54.  
  55. # create an open button which uses the open_file function
  56. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  57.  
  58.  
  59. #create a place for text preferences called pref controls
  60. pref_controls = Box(app, align="bottom", width="fill", border=True)
  61.  
  62. #create some padding for the pref_controls box
  63. pad2 = Box(pref_controls, align="left", width=8, height= 1)
  64.  
  65. #create the Combo for Font Selection
  66. font = Combo(pref_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font,)
  67.  
  68. #Font Size Changer
  69. size = Slider(pref_controls,  align="left", command=change_text_size, start=10, end=18)
  70.  
  71. #Font Colour Changer
  72. colur = Combo(pref_controls, options=["green", "red", "blue", "black"],align="left", command=change_colour)
  73.  
  74.  
  75. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement