Advertisement
kalpin

TextEditor v1

Aug 4th, 2020
1,629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.51 KB | None | 0 0
  1. from guizero import App, Box, PushButton, TextBox, Combo, Text, info
  2.  
  3. app = App(title="Text Editor",width="800",height="600")
  4.  
  5. # Event Handlers
  6.  
  7. def btnSaveClicked():
  8.     f =  open(txtFilename.value, "w")
  9.     f.write(txtEditor.value)
  10.     f.close()
  11.     info('SAVE','Your file has been saved')
  12.  
  13. def btnLoadClicked():
  14.     with open(txtFilename.value, "r") as f:
  15.         txtEditor.value = f.read()
  16.  
  17. def cboBgChanged():
  18.     boxEditor.bg = cboBg.value
  19.  
  20. def cboFontChanged():
  21.     boxEditor.font = cboFont.value
  22.  
  23. def cboFontSizeChanged():
  24.     boxEditor.text_size = int(cboFontSize.value)
  25.  
  26. # Your GUI widgets go here
  27.  
  28. ####################################################################
  29.  
  30. boxFileControls = Box(app, align="top", width='fill', height = 30)
  31. boxFileControls.bg = "forest green"
  32. boxFileControls.text_color = 'white'
  33. btnOpen = PushButton(boxFileControls, align="left", text = "Open", width = 15, command = btnLoadClicked)
  34. btnSave = PushButton(boxFileControls, align="left", text = "Save", width = 15, command = btnSaveClicked)
  35. txtFilename = TextBox(boxFileControls, text = 'editor.txt', width = 20, height = 'fill', align = 'right')
  36. lblFilename = Text(boxFileControls, text = 'Filename:',align = 'right',size = 12)
  37.  
  38. ####################################################################
  39.  
  40. boxMenu = Box(app, align="top", width='fill', height = 25  )
  41. boxMenu.bg ='deep sky blue'
  42. lblFont = Text(boxMenu, text="Font: ", color = 'black', align = 'left')
  43. cboFont = Combo(boxMenu, options=["Palatino Linotype","Arial","Segoe UI", "Times New Roman","Courier New"], width = 20, height = 'fill', align = 'left', command = cboFontChanged)
  44. lblBg = Text(boxMenu, text="Background: ", color = 'black', align = 'left')
  45. cboBg = Combo(boxMenu, options=["light yellow", "linen", "honeydew", "LightBlue1", "gray98", "white"], width = 20, height = 'fill', align = 'left', command = cboBgChanged)
  46. lblFontSize = Text(boxMenu, text="Size: ", color = 'black', align = 'left')
  47. cboFontSize = Combo(boxMenu, options=[10,12,14,16,18], width = 20, height = 'fill', align = 'left', command = cboFontSizeChanged)
  48.  
  49. ####################################################################
  50.  
  51. boxEditor = Box(app, align = 'top', width='fill', height = 'fill', border = 1)
  52. boxEditor.bg = 'light yellow'
  53. boxEditor.font ='Palatino Linotype'
  54. txtEditor = TextBox(boxEditor, width = 'fill', height = 'fill', multiline = True, scrollbar = True)
  55.  
  56. ####################################################################
  57.  
  58. # Show the GUI on the screen
  59. app.display()
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement