Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, PushButton, Box, Combo, CheckBox, Slider, MenuBar, Text
- def file_function():
- print("File option")
- def edit_function():
- print("Edit option")
- 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()
- # This is where any additional functions needed to run your script go
- def change_font():
- editor.font = font.value
- def change_text_size():
- editor.text_size = size.value
- editor.resize(1, 1)
- editor.resize("fill", "fill")
- def change_text_color():
- editor.text_color = color.value
- def change_theme():
- if dark_theme.value:
- app.bg = "black"
- app.text_color = "white"
- else:
- app.bg = None
- app.text_color = None
- app = App(title="textzero")
- # The new MenuBar
- menubar = MenuBar(app,
- toplevel=["File", "Edit"],
- options=[
- [ ["File option 1", file_function], ["File option 2", file_function] ],
- [ ["Edit option 1", edit_function], ["Edit option 2", edit_function] ]
- ])
- file_controls = Box(app, align="top", 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")
- editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
- # This is where your additional features go
- preferences_controls = Box(app, align="bottom", width="fill", border=True)
- font = Combo(preferences_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font)
- size = Slider(preferences_controls, align="left", start = 8, end = 42, command=change_text_size)
- color = Combo(preferences_controls, options=["red", "orange", "navy"],align="left", command=change_text_color)
- dark_theme = CheckBox(preferences_controls, text="dark", align="left", command=change_theme)
- message = Text(app, text="TextZero Control Panel - Change font, colour, text-size and theme below", size=8, bg ="yellow" )
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement