2018-12-21 19:44:08 +00:00
|
|
|
import PySimpleGUI as sg
|
|
|
|
import random
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
# Bars drawing in PySimpleGUI
|
|
|
|
#
|
|
|
|
# .--.
|
|
|
|
# | |
|
|
|
|
# .--.| |.--.
|
|
|
|
# | || || |
|
|
|
|
# | || || |
|
|
|
|
# | || || |
|
|
|
|
# .--.| || || |
|
|
|
|
# .--.| || || || |.--.
|
|
|
|
# | || || || || || |
|
|
|
|
# | || || || || || |
|
|
|
|
# .--.| || || || || || |.--.
|
|
|
|
# | || || || || || || || |.--.
|
|
|
|
# | || || || || || || || || |
|
|
|
|
# '--''--''--''--''--''--''--''--''--'
|
|
|
|
|
|
|
|
|
2018-12-21 19:44:08 +00:00
|
|
|
BAR_WIDTH = 50
|
|
|
|
BAR_SPACING = 75
|
|
|
|
EDGE_OFFSET = 3
|
|
|
|
GRAPH_SIZE = (500,500)
|
|
|
|
DATA_SIZE = (500,500)
|
|
|
|
|
2019-12-24 23:52:47 +00:00
|
|
|
sg.theme('Light Brown 1')
|
2019-12-08 00:27:01 +00:00
|
|
|
|
2019-09-20 20:59:15 +00:00
|
|
|
graph = sg.Graph(GRAPH_SIZE, (0,0), DATA_SIZE)
|
2018-12-21 19:44:08 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
layout = [[sg.Text('Labelled Bar graphs using PySimpleGUI')],
|
2018-12-21 19:44:08 +00:00
|
|
|
[graph],
|
2019-10-23 20:10:03 +00:00
|
|
|
[sg.Button('OK'), sg.T('Click to display more data'), sg.Exit()]]
|
2018-12-21 19:44:08 +00:00
|
|
|
|
2019-09-20 20:59:15 +00:00
|
|
|
window = sg.Window('Window Title', layout)
|
2018-12-21 19:44:08 +00:00
|
|
|
|
|
|
|
while True:
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read()
|
2020-05-07 10:22:59 +00:00
|
|
|
if event in (sg.WIN_CLOSED, 'Exit'):
|
2018-12-21 19:44:08 +00:00
|
|
|
break
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
graph.erase()
|
2018-12-21 19:44:08 +00:00
|
|
|
for i in range(7):
|
|
|
|
graph_value = random.randint(0, 400)
|
2019-10-23 20:10:03 +00:00
|
|
|
graph.draw_rectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value),
|
2018-12-21 19:44:08 +00:00
|
|
|
bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0), fill_color='blue')
|
2019-10-23 20:10:03 +00:00
|
|
|
graph.draw_text(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10))
|
|
|
|
window.close()
|