Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rom guizero import App, Text, PushButton, TextBox, Box, Combo, CheckBox, MenuBar
- # function to save and open file
- 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)
- save_button.disable()
- def enable_save():
- save_button.enable()
- # A new function that closes the app
- def exit_app():
- app.destroy()
- def change_font():
- editor.font = font.value
- #function to resize text
- 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")
- # function to change font color and theme
- def change_color():
- editor.text_color = color.value
- def change_theme():
- if theme.value == 1:
- app.bg = "black"
- app.text_color = "white"
- else:
- app.bg = None
- app.text_color = None
- # function to make menubar preferences show
- def pref_fontis():
- font_box.show()
- def pref_sizes():
- size_box.show()
- def pref_colour():
- color_box.show()
- def pref_theme():
- theme_box.show()
- def hide_pref():
- font_box.hide()
- size_box.hide()
- color_box.hide()
- theme_box.hide()
- app = App(title="TextZero Editor")
- # The new MenuBar
- menubar = MenuBar(app,
- toplevel=["File", "Prefs"],
- options=[
- [ ["Open",open_file],["Save",save_file],["Exit",exit_app] ],
- [ ["Font",pref_fontis],["Size",pref_sizes],["Colour",pref_colour],["Theme",pref_theme],["Close pref",hide_pref] ]
- ])
- # Box control on the bottom with save and open file
- file_controls = Box(app, align="bottom", width="fill", border=True)
- file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
- save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
- open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
- # Box contain preferences control
- preferences_control = Box(app, layout='auto', align="top", width="fill")
- font_box = Box(preferences_control, align="left", width="fill",border=True, visible=False)
- size_box= Box(preferences_control, align="left", width="fill",border=True, visible=False)
- color_box= Box(preferences_control, align="left", width="fill",border=True, visible=False)
- theme_box = Box(preferences_control, align="left", width="fill",border=True, visible=False)
- # Editor of the text that multiline writing
- editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
- # Widget that use on the editor
- label_font = Text(font_box, align="left", text="Font: ")
- font = Combo(font_box, options=["courier", "times new roman", "verdana"], align="left", command=change_font)
- label_size = Text(size_box, align="left", text="Size: ")
- size = Combo(size_box, options=["8", "10", "12","16"], align="left", command=change_text_size)
- label_color = Text(color_box, align="left", text="Colour: ")
- color = Combo(color_box, options=["red","green","black"], align="left", command=change_color)
- label_theme = Text(theme_box, text='Dark mode', align="left")
- theme = CheckBox(theme_box, align="left", command=change_theme)
- # Display on the screen
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement