Skip to content

Instantly share code, notes, and snippets.

@fx-kirin
Last active June 16, 2020 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fx-kirin/c6fef5689b30d1e73f6a6229a165f29e to your computer and use it in GitHub Desktop.
Save fx-kirin/c6fef5689b30d1e73f6a6229a165f29e to your computer and use it in GitHub Desktop.
Orderbook example with PySimpleGui
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2020 fx-kirin <fx.kirin@gmail.com>
#
from random import randint
import PySimpleGUI as sg
"""
Basic use of the Table Element
"""
sg.theme("DarkBrown1")
# ------ Some functions to help generate data for the table ------
def make_table(size):
data = []
prices = list(reversed(sorted([randint(100, 1000) for r in range(size * 2)])))
for price in prices[:size]:
data.append([randint(1, 10), randint(1, 20) * 100, price, "", ""])
for price in prices[size:]:
data.append(["", "", price, randint(1, 20) * 100, randint(1, 10)])
return data
def main():
# ------ Make the Table Data ------
data = make_table(10)
# ------ Create Window ------
layout = [
[
sg.Table(
values=data,
headings=["num_ask", "ask", "price", "bid", "num_bid"],
max_col_width=25,
justification="right",
num_rows=20,
alternating_row_color="#111111",
key="-TABLE-",
row_height=35,
tooltip="This is a table",
)
],
[sg.Button("Next")],
]
window = sg.Window("The Table Element", layout)
# ------ Event Loop ------
while True:
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED:
break
if event == "Next":
data = make_table(10)
window["-TABLE-"].update(values=data)
window.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment