Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1.  
  2. <!-- %!% -->
  3. ## Output Element
  4. Output re-routes `Stdout` to a scrolled text box.
  5.  
  6. Whatever you print will show up in this window.
  7.  
  8. Note that you will NOT see what you print until you call either window.Read or window.Refresh. If you want to immediately see what was printed, call window.Refresh() immediately after your print statement.
  9.  
  10. <!-- <+Output.doc+> -->
  11.  
  12. ```python
  13. layout = [[sg.Output(size=(80,10)]]
  14. ```
  15.  
  16. ![output](https://user-images.githubusercontent.com/13696193/44959863-b72f8280-aec3-11e8-8caa-7bc743149953.jpg)
  17.  
  18. <!-- <+Output.__init__+> -->
  19.  
  20. <!--
  21. ```python
  22. Output(size=(None, None),
  23. background_color=None,
  24. text_color=None,
  25. pad=None,
  26. font=None,
  27. tooltip=None,
  28. right_click_menu=None,
  29. key=None,
  30. visible=True)
  31. ```
  32.  
  33. size - Size of Output Element (width, height) in characters
  34. You should be quite familiar with these parameters by now. If not, read able another element or read about common parameters.
  35. -->
  36.  
  37.  
  38. ## Input Elements
  39. These make up the majority of the window definition. Optional variables at the Element level override the window level values (e.g. `size` is specified in the Element). All input Elements create an entry in the list of return values. A Text Input Element creates a string in the list of items returned.
  40.  
  41.  
  42.  
  43.  
  44.  
  45. #### Output Element
  46. The Output Element is a re-direction of Stdout. Anything "printed" will be displayed in this element.
  47.  
  48. <!-- <+Output.doc+> -->
  49.  
  50. ```python
  51. Output(size=(None, None))
  52. ```
  53.  
  54. Here's a complete solution for a chat-window using an Async window with an Output Element
  55.  
  56. ```python
  57. import PySimpleGUI as sg
  58.  
  59. # Blocking window that doesn't close
  60. def ChatBot():
  61. layout = [[(sg.Text('This is where standard out is being routed', size=[40, 1]))],
  62. [sg.Output(size=(80, 20))],
  63. [sg.Multiline(size=(70, 5), enter_submits=True),
  64. sg.RButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0])),
  65. sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]]
  66.  
  67. window = sg.Window('Chat Window', default_element_size=(30, 2)).Layout(layout)
  68.  
  69. # ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
  70. while True:
  71. event, value = window.Read()
  72. if event == 'SEND':
  73. print(value)
  74. else:
  75. break
  76.  
  77. ChatBot()
  78. ```
  79.  
  80. <!-- <+Output.__init__+> -->
  81.  
  82.  
  83. ### Methods
  84.  
  85. <!-- <+Output.UpdateBar+> -->
  86.  
  87.  
  88. <!-- ```python
  89. UpdateBar(current_count, max=None)
  90. ```
  91. current_count - sets the current value
  92. max - changes the max value
  93. -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement