Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, Slider, Box, Text, ButtonGroup, PushButton, Combo, CheckBox, ListBox, Picture
- def open_file():
- with open (file_name.value, "r") as f:
- editor.value = f.read()
- def save_file():
- with open (file_name.value, "w") as f:
- f.write (editor.value)
- # Disable the save_button
- save_button.disable()
- def enable_save():
- save_button.enable()
- save_button.show()
- def change_text_font():
- editor.font = font_list.value[font_select]
- def change_text_color():
- editor.color = "red"#color_list[1]#color_select.value]
- def change_text_size():
- editor.text_size = size.value
- # 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
- editor.resize(1, 1)
- editor.resize("fill", "fill")
- app = App(title="texteditor")
- font_list = ['times new roman','helvetica','gothic','mincho']
- color_list = ['black','red','tan','blue','green','cyan','yellow','megenta','gray']
- # create a box to house the controls, we want the box to span the entire width of the app
- file_controls = Box(app, align="top", width="fill")
- # create a TextBox for the file name
- file_name = TextBox(file_controls, text="text_file.txt", width=28, align="left")
- # create a save button which uses the save_file function
- save_button = PushButton(file_controls, text="Save", align="right", height= 1)
- save_button.command=save_file
- save_button.disable()
- save_button.hide()
- # create an open button which uses the open_file function
- open_button = PushButton(file_controls, text="Open", align="right", height= 1)
- open_button.command=open_file
- #
- # create a TextBox which is not in the box and fills the rest of the GUI
- editor = TextBox(app, multiline=True, height="fill", width="fill",command=enable_save)
- preferences_controls = Box(app, align="bottom", width="fill", border=True)
- #create a font combo
- # Times New Roman 12
- # helvetica 12
- # gothic 13
- # mincho 13
- font_select = Combo(preferences_controls, align="right",width="fill", height= 1, options=font_list, selected=font_list[0])
- font_select.command=change_text_font
- color_select = Combo(preferences_controls, align="right",width="fill", height= 1, options=color_list, selected=color_list[0])
- color_select.command=change_text_color
- size = Slider(preferences_controls, align="left", start = 8, end = 42, command=change_text_size)
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement