Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- %!% -->
- ## Output Element
- Output re-routes `Stdout` to a scrolled text box.
- Whatever you print will show up in this window.
- 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.
- <!-- <+Output.doc+> -->
- ```python
- layout = [[sg.Output(size=(80,10)]]
- ```
- ![output](https://user-images.githubusercontent.com/13696193/44959863-b72f8280-aec3-11e8-8caa-7bc743149953.jpg)
- <!-- <+Output.__init__+> -->
- <!--
- ```python
- Output(size=(None, None),
- background_color=None,
- text_color=None,
- pad=None,
- font=None,
- tooltip=None,
- right_click_menu=None,
- key=None,
- visible=True)
- ```
- size - Size of Output Element (width, height) in characters
- You should be quite familiar with these parameters by now. If not, read able another element or read about common parameters.
- -->
- ## Input Elements
- 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.
- #### Output Element
- The Output Element is a re-direction of Stdout. Anything "printed" will be displayed in this element.
- <!-- <+Output.doc+> -->
- ```python
- Output(size=(None, None))
- ```
- Here's a complete solution for a chat-window using an Async window with an Output Element
- ```python
- import PySimpleGUI as sg
- # Blocking window that doesn't close
- def ChatBot():
- layout = [[(sg.Text('This is where standard out is being routed', size=[40, 1]))],
- [sg.Output(size=(80, 20))],
- [sg.Multiline(size=(70, 5), enter_submits=True),
- sg.RButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0])),
- sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]]
- window = sg.Window('Chat Window', default_element_size=(30, 2)).Layout(layout)
- # ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
- while True:
- event, value = window.Read()
- if event == 'SEND':
- print(value)
- else:
- break
- ChatBot()
- ```
- <!-- <+Output.__init__+> -->
- ### Methods
- <!-- <+Output.UpdateBar+> -->
- <!-- ```python
- UpdateBar(current_count, max=None)
- ```
- current_count - sets the current value
- max - changes the max value
- -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement