Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, Text, TextBox, Box, MenuBar, Combo, Slider, info
- # These are the functions that are called by selecting options from each submenu
- editor_text_saved = False
- 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)
- editor.bg="White"
- def exit_app():
- if (editor.bg == "Light Grey"):
- info("Warning","You must save file before exit ...")
- else:
- app.destroy()
- def clear_text():
- editor.clear()
- def wonb():
- if (editor.bg == "Light Grey"):
- info("Warning","You must save file before doing this ...")
- else:
- editor.bg= "black"
- editor.text_color= "white"
- def bonw():
- if (editor.bg == "Light Grey"):
- info("Warning","You must save file before doing this ...")
- else:
- editor.bg= "white"
- editor.text_color= "black"
- # This is a text editor with menu
- app = App(title="Text Editor with menu")
- # The new MenuBar
- menubar = MenuBar(app,
- toplevel=["File","Options"],
- options=[[["open",open_file],["save",save_file],["exit",exit_app]],
- [["clear",clear_text],["white on black",wonb],["black on white",bonw]]])
- file_controls = Box(app, align="top", width="fill")
- font_controls = Box(app, align="top", width="fill", )
- file_label = Text(file_controls, text="File Name", width=10, align="left")
- file_name = TextBox(file_controls, text="Infinito.txt", width=50, align="left")
- # function to select font
- def select_font():
- editor.font= font_choice.value
- # menu to select a font
- font_choice = Combo(font_controls, options=["Bitstream", "Courier", "eufm10", "Helvetica", "Purisa", "Times"],
- selected="Bitstream", command=select_font, width=10, align="left")
- # function to select font color
- def select_color():
- editor.text_color= font_color.value
- # menu to select a font
- font_color = Combo(font_controls, options=["Yellow", "Blue", "Green", "Black", "Red", "Violet"],
- selected="Grey", command=select_color, width=10, align="left")
- # create a Text for the font size
- font_size_label = Text(font_controls, text="Font Size", width=10, align="left")
- # function to select font size
- def slider_changed(slider_value):
- editor.text_size= font_size.value
- font_size = Slider(font_controls, command=slider_changed, start=10, end=40, width=80, align="left")
- def set_not_saved():
- editor.bg="Light Grey"
- editor = TextBox(app, multiline=True, scrollbar=True, height="fill", width="fill", command=set_not_saved)
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement