Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, Box, PushButton, TextBox, Combo, Text, info, Window
- 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 ChangeBgcolour():
- boxEditor.bg = cboChangeBg.value
- bgWindow.hide()
- def btnChangeFontSize():
- fontSizeWindow.show(wait=True)
- def btnChangeFont():
- fontWindow.show(wait = True)
- def btnChangeBg():
- bgWindow.show(wait = True)
- def FontChanged():
- boxEditor.font = cboChangeFont.value
- fontWindow.hide()
- def ChangeFontSize():
- boxEditor.text_size = int(cboChangeFontSize.value)
- fontSizeWindow.hide()
- def cboCancel():
- fontWindow.hide()
- def cboCancel2():
- fontSizeWindow.hide()
- def cboCancel3():
- bgWindow.hide()
- # Your GUI widgets go here
- ####################################################################
- boxFileControls = Box(app, align="top", width='fill', height = 50)
- boxFileControls.bg = "white"
- boxFileControls.text_color = 'black'
- btnOpen = PushButton(boxFileControls, align="left", text = "", image = "store-files.jpg", width = 40, height = 40, command = btnLoadClicked)
- lblBlank = Text(boxFileControls,text = '', width = 1, align = 'left')
- btnSave = PushButton(boxFileControls, align="left", text = "", image = "save-files.jpg", command = btnSaveClicked)
- lblBlank = Text(boxFileControls,text = '', width = 5, align = 'left')
- btnFont = PushButton(boxFileControls, align="left", text = "", image = "font.jpg", width = 40, height = 40, command = btnChangeFont)
- lblBlank = Text(boxFileControls,text = '', width = 1, align = 'left')
- btnSize = PushButton(boxFileControls, align="left", text = "", image = "text.jpg", width = 40, height = 40, command = btnChangeFontSize)
- lblBlank = Text(boxFileControls,text = '', width = 1, align = 'left')
- btnBg = PushButton(boxFileControls, align="left", text = "", image = "bg.jpg", width = 40, height = 40, command = btnChangeBg)
- txtFilename = TextBox(boxFileControls, text = 'editor.txt', width = 20, height = 'fill', align = 'right')
- txtFilename.text_size =12
- ####################################################################
- 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)
- ####################################################################
- # Windows
- # Font Window
- fontWindow = Window(app,"Change Font",width = 300, height = 200)
- fontWindow.bg = 'light blue'
- fontWindow.font='Segoe Ui'
- fontWindow.hide()
- lblChangeFont = Text(fontWindow, text = "Select a font", align='top')
- cboChangeFont = Combo(fontWindow, options = ['Times New Roman','Courier New', 'Palatino Linotype', 'Segoe UI'],align = 'top')
- btnSubmit1 = PushButton(fontWindow, text = 'OK', align = 'left', width = 20, command = FontChanged)
- btnCancel1 = PushButton(fontWindow, text = 'CANCEL', align = 'left', width = 20, command = cboCancel)
- # Font Size Window
- fontSizeWindow = Window(app,"Change Font Size",width = 300, height = 200)
- fontSizeWindow.bg = 'light blue'
- fontSizeWindow.font='Segoe Ui'
- fontSizeWindow.hide()
- lblChangeFontSize = Text(fontSizeWindow, text = "Select a size",align="top")
- cboChangeFontSize = Combo(fontSizeWindow, options = ['10','12','14','16','18'],align="top")
- btnSubmit2 = PushButton(fontSizeWindow, text = 'OK', align = 'left', width = 20, command = ChangeFontSize)
- btnCancel2 = PushButton(fontSizeWindow, text = 'CANCEL', align = 'left', width = 20, command = cboCancel2)
- # Background Colour Window
- bgWindow = Window(app,"Change Background Colour",width = 300, height = 200)
- bgWindow.bg = 'light blue'
- bgWindow.font='Segoe Ui'
- bgWindow.hide()
- lblChangeBg= Text(bgWindow, text = "Select a colour",align="top")
- cboChangeBg = Combo(bgWindow, options = ['light yellow','honeydew','light blue','lavender','pink'],align="top")
- btnSubmit3 = PushButton(bgWindow, text = 'OK', align = 'left', width = 20, command = ChangeBgcolour)
- btnCancel3 = PushButton(bgWindow, text = 'CANCEL', align = 'left', width = 20, command = cboCancel3)
- ####################################################################
- # Show the GUI on the screen
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement