Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, Box, PushButton, TextBox, Combo, Text, info
- app = App(title="Text Editor",width="800",height="600")
- # Event Handlers
- def btnSaveClicked():
- f = open(txtFilename.value, "w")
- f.write(txtEditor.value)
- f.close()
- info('SAVE','Your file has been saved')
- def btnLoadClicked():
- with open(txtFilename.value, "r") as f:
- txtEditor.value = f.read()
- def cboBgChanged():
- boxEditor.bg = cboBg.value
- def cboFontChanged():
- boxEditor.font = cboFont.value
- def cboFontSizeChanged():
- boxEditor.text_size = int(cboFontSize.value)
- # Your GUI widgets go here
- ####################################################################
- boxFileControls = Box(app, align="top", width='fill', height = 30)
- boxFileControls.bg = "forest green"
- boxFileControls.text_color = 'white'
- btnOpen = PushButton(boxFileControls, align="left", text = "Open", width = 15, command = btnLoadClicked)
- btnSave = PushButton(boxFileControls, align="left", text = "Save", width = 15, command = btnSaveClicked)
- txtFilename = TextBox(boxFileControls, text = 'editor.txt', width = 20, height = 'fill', align = 'right')
- lblFilename = Text(boxFileControls, text = 'Filename:',align = 'right',size = 12)
- ####################################################################
- boxMenu = Box(app, align="top", width='fill', height = 25 )
- boxMenu.bg ='deep sky blue'
- lblFont = Text(boxMenu, text="Font: ", color = 'black', align = 'left')
- cboFont = Combo(boxMenu, options=["Palatino Linotype","Arial","Segoe UI", "Times New Roman","Courier New"], width = 20, height = 'fill', align = 'left', command = cboFontChanged)
- lblBg = Text(boxMenu, text="Background: ", color = 'black', align = 'left')
- cboBg = Combo(boxMenu, options=["light yellow", "linen", "honeydew", "LightBlue1", "gray98", "white"], width = 20, height = 'fill', align = 'left', command = cboBgChanged)
- lblFontSize = Text(boxMenu, text="Size: ", color = 'black', align = 'left')
- cboFontSize = Combo(boxMenu, options=[10,12,14,16,18], width = 20, height = 'fill', align = 'left', command = cboFontSizeChanged)
- ####################################################################
- boxEditor = Box(app, align = 'top', width='fill', height = 'fill', border = 1)
- boxEditor.bg = 'light yellow'
- boxEditor.font ='Palatino Linotype'
- txtEditor = TextBox(boxEditor, width = 'fill', height = 'fill', multiline = True, scrollbar = True)
- ####################################################################
- # Show the GUI on the screen
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement