crzcas

GUI with control

Mar 7th, 2021
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. from guizero import App, Text, TextBox, PushButton, Box, Combo, CheckBox, Slider
  2.  
  3. app = App(title="textzero", bg = "gold")
  4.  
  5. def open_file():
  6.     with open(file_name.value, "r") as f:
  7.         editor.value = f.read()
  8.  
  9. def save_file():
  10.     with open(file_name.value, "w") as f:
  11.         f.write(editor.value)
  12.  
  13. def change_font():
  14.     editor.font = font.value
  15.  
  16. def change_text_size():
  17.     editor.text_size = size.value
  18.     editor.resize(1, 1)
  19.     editor.resize("fill", "fill")
  20.    
  21. def set_colour():
  22.     text_b.text_color = font_colour.value    
  23.  
  24.  
  25. file_controls = Box(app, align="top", width="fill", border=True)
  26. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  27. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  28. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  29.  
  30. editor = TextBox(app, multiline=True, height="fill", width="fill")
  31.  
  32. colours = ["red",
  33.             "black",
  34.             "green",
  35.             "orange"]
  36.  
  37. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  38. font = Combo(preferences_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font)
  39. size = Slider(preferences_controls,  align="left", start = 8, end = 42, command=change_text_size)
  40. font_colour = Combo(preferences_controls, align = 'left', options = colours, command = set_colour)
  41.  
  42. app.display()
Advertisement
Add Comment
Please, Sign In to add comment