Advertisement
kalpin

Text Editor v 2

Aug 5th, 2020
1,281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.48 KB | None | 0 0
  1. from guizero import App, Box, PushButton, TextBox, Combo, Text, info, Window
  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 ChangeBgcolour():
  18.     boxEditor.bg = cboChangeBg.value
  19.     bgWindow.hide()
  20.  
  21. def btnChangeFontSize():
  22.     fontSizeWindow.show(wait=True)
  23.    
  24. def btnChangeFont():
  25.     fontWindow.show(wait = True)
  26.  
  27. def btnChangeBg():
  28.     bgWindow.show(wait = True)
  29.    
  30.        
  31. def FontChanged():
  32.     boxEditor.font = cboChangeFont.value
  33.     fontWindow.hide()
  34.    
  35. def ChangeFontSize():
  36.     boxEditor.text_size = int(cboChangeFontSize.value)
  37.     fontSizeWindow.hide()
  38.  
  39. def cboCancel():
  40.     fontWindow.hide()
  41.  
  42. def cboCancel2():
  43.     fontSizeWindow.hide()
  44.  
  45. def cboCancel3():
  46.     bgWindow.hide()
  47.    
  48. # Your GUI widgets go here
  49.  
  50. ####################################################################
  51.  
  52. boxFileControls = Box(app, align="top", width='fill', height = 50)
  53. boxFileControls.bg = "white"
  54. boxFileControls.text_color = 'black'
  55. btnOpen   = PushButton(boxFileControls, align="left", text = "", image = "store-files.jpg", width = 40, height = 40, command = btnLoadClicked)
  56. lblBlank  = Text(boxFileControls,text = '', width = 1, align = 'left')
  57. btnSave   = PushButton(boxFileControls, align="left", text = "", image = "save-files.jpg",  command = btnSaveClicked)
  58. lblBlank  = Text(boxFileControls,text = '', width = 5, align = 'left')
  59. btnFont   = PushButton(boxFileControls, align="left", text = "", image = "font.jpg", width = 40, height = 40, command = btnChangeFont)
  60. lblBlank  = Text(boxFileControls,text = '', width = 1, align = 'left')
  61. btnSize   = PushButton(boxFileControls, align="left", text = "", image = "text.jpg", width = 40, height = 40, command = btnChangeFontSize)
  62. lblBlank  = Text(boxFileControls,text = '', width = 1, align = 'left')
  63. btnBg     = PushButton(boxFileControls, align="left", text = "", image = "bg.jpg", width = 40, height = 40, command = btnChangeBg)
  64. txtFilename = TextBox(boxFileControls, text = 'editor.txt', width = 20, height = 'fill', align = 'right')
  65. txtFilename.text_size =12
  66.  
  67. ####################################################################
  68.  
  69. boxEditor = Box(app, align = 'top', width='fill', height = 'fill', border = 1)
  70. boxEditor.bg = 'light yellow'
  71. boxEditor.font ='Palatino Linotype'
  72. txtEditor = TextBox(boxEditor, width = 'fill', height = 'fill', multiline = True, scrollbar = True)
  73.  
  74. ####################################################################
  75.  
  76. # Windows
  77.  
  78. # Font Window
  79. fontWindow = Window(app,"Change Font",width = 300, height = 200)
  80. fontWindow.bg = 'light blue'
  81. fontWindow.font='Segoe Ui'
  82. fontWindow.hide()
  83.  
  84. lblChangeFont = Text(fontWindow, text = "Select a font", align='top')
  85. cboChangeFont = Combo(fontWindow, options = ['Times New Roman','Courier New', 'Palatino Linotype', 'Segoe UI'],align = 'top')
  86. btnSubmit1 = PushButton(fontWindow, text = 'OK', align = 'left', width = 20, command = FontChanged)
  87. btnCancel1 = PushButton(fontWindow, text = 'CANCEL', align = 'left', width = 20, command = cboCancel)
  88.  
  89. # Font Size Window
  90. fontSizeWindow = Window(app,"Change Font Size",width = 300, height = 200)
  91. fontSizeWindow.bg = 'light blue'
  92. fontSizeWindow.font='Segoe Ui'
  93. fontSizeWindow.hide()
  94.  
  95. lblChangeFontSize = Text(fontSizeWindow, text = "Select a size",align="top")
  96. cboChangeFontSize = Combo(fontSizeWindow, options = ['10','12','14','16','18'],align="top")
  97. btnSubmit2 = PushButton(fontSizeWindow, text = 'OK', align = 'left', width = 20, command = ChangeFontSize)
  98. btnCancel2 = PushButton(fontSizeWindow, text = 'CANCEL', align = 'left', width = 20, command = cboCancel2)
  99.  
  100. # Background Colour Window
  101. bgWindow = Window(app,"Change Background Colour",width = 300, height = 200)
  102. bgWindow.bg = 'light blue'
  103. bgWindow.font='Segoe Ui'
  104. bgWindow.hide()
  105.  
  106. lblChangeBg= Text(bgWindow, text = "Select a colour",align="top")
  107. cboChangeBg = Combo(bgWindow, options = ['light yellow','honeydew','light blue','lavender','pink'],align="top")
  108. btnSubmit3 = PushButton(bgWindow, text = 'OK', align = 'left', width = 20, command = ChangeBgcolour)
  109. btnCancel3 = PushButton(bgWindow, text = 'CANCEL', align = 'left', width = 20, command = cboCancel3)
  110.  
  111. ####################################################################
  112. # Show the GUI on the screen
  113. app.display()
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement