Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox,Text, PushButton, Box, Slider, ButtonGroup
- from time import sleep
- def dofonts():
- sl_fontsize.show()
- bg_fontcolour.show()
- bt_fontstuff.disable()
- bt_endfonts.show()
- def finished():
- sl_fontsize.hide()
- bg_fontcolour.hide()
- bt_fontstuff.enable()
- bt_endfonts.hide()
- def fontsize():
- editor.text_size = sl_fontsize.value
- def fontcolour():
- editor.text_color = bg_fontcolour.value
- def open_file():
- with open(file_name.value, "r") as f:
- editor.value = f.read()
- # function for writing files
- def save_file():
- with open(file_name.value, "w") as f:
- f.write(editor.value)
- app = App(title="My Text Editor in Python", width=640, height=480, layout="grid")
- app.bg=(204,204,255)
- # create a box to house the controls, we want the box to span the entire width of the app
- file_controls = Box(app, align="left", height=20, width=560, grid=[0,0])
- # create a TextBox for the file name
- txt_filelabel=Text(file_controls,text="File Name: ",size=8, align="left")
- file_name = TextBox(file_controls, text="example.txt", width=50, align="left")
- file_name.bg=(255,255,255)
- # create a TextBox which is not in the box and fills the rest of the GUI
- editspace = Box(app, align="top", height=460, width=560, grid=[0,1])
- editor = TextBox(editspace, multiline=True, height="fill", width="fill", scrollbar=True)
- editspace.bg=(255,255,255)
- # create a save button which uses the save_file function
- buttonspace = Box(app, align="top", width=80, height=480, grid=[1,0,1,2])
- save_button = PushButton(buttonspace, width=6, text="Save", command=save_file)
- save_button.bg=(255,204,204)
- # create an open button which uses the open_file function
- open_button = PushButton(buttonspace, text="Open", width=6, command=open_file)
- open_button.bg=(204,255,204)
- bt_fontstuff = PushButton(buttonspace, text="Font Stuff", width=6, command=dofonts)
- # create a slider for font size
- sl_fontsize = Slider(buttonspace,start=6,end=36,horizontal=False, command=fontsize)
- sl_fontsize.hide()
- # create a button group for text colour
- bg_fontcolour = ButtonGroup(buttonspace, options=["Black", "Red", "Green", "Blue"], selected="Black", command=fontcolour)
- bg_fontcolour.hide()
- bt_endfonts = PushButton(buttonspace, text="Finish", width=6, command=finished)
- bt_endfonts.hide()
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement