Merge pull request #5152 from PySimpleGUI/Dev-latest
Updated Bar Char Demo - I thought this update was done long long ago!…
This commit is contained in:
commit
c423e4ce8e
|
@ -19,31 +19,37 @@ import random
|
||||||
# '--''--''--''--''--''--''--''--''--'
|
# '--''--''--''--''--''--''--''--''--'
|
||||||
|
|
||||||
|
|
||||||
BAR_WIDTH = 50
|
BAR_WIDTH = 50 # width of each bar
|
||||||
BAR_SPACING = 75
|
BAR_SPACING = 75 # space between each bar
|
||||||
EDGE_OFFSET = 3
|
EDGE_OFFSET = 3 # offset from the left edge for first bar
|
||||||
GRAPH_SIZE = (500,500)
|
GRAPH_SIZE= DATA_SIZE = (500,500) # size in pixels
|
||||||
DATA_SIZE = (500,500)
|
|
||||||
|
|
||||||
sg.theme('Light Brown 1')
|
sg.theme('Light brown 1')
|
||||||
|
|
||||||
graph = sg.Graph(GRAPH_SIZE, (0,0), DATA_SIZE)
|
|
||||||
|
|
||||||
layout = [[sg.Text('Labelled Bar graphs using PySimpleGUI')],
|
layout = [[sg.Text('Labelled Bar graphs using PySimpleGUI')],
|
||||||
[graph],
|
[sg.Graph(GRAPH_SIZE, (0,0), DATA_SIZE, k='-GRAPH-')],
|
||||||
[sg.Button('OK'), sg.T('Click to display more data'), sg.Exit()]]
|
[sg.Button('OK'), sg.T('Click to display more data'), sg.Exit()]]
|
||||||
|
|
||||||
window = sg.Window('Window Title', layout)
|
window = sg.Window('Bar Graph', layout, finalize=True)
|
||||||
|
|
||||||
|
graph = window['-GRAPH-'] # type: sg.Graph
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
event, values = window.read()
|
|
||||||
if event in (sg.WIN_CLOSED, 'Exit'):
|
|
||||||
break
|
|
||||||
|
|
||||||
graph.erase()
|
graph.erase()
|
||||||
for i in range(7):
|
for i in range(7):
|
||||||
graph_value = random.randint(0, 400)
|
graph_value = random.randint(0, GRAPH_SIZE[1])
|
||||||
graph.draw_rectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value),
|
graph.draw_rectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value),
|
||||||
bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0), fill_color='blue')
|
bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0),
|
||||||
|
fill_color=sg.theme_button_color()[1])
|
||||||
|
|
||||||
graph.draw_text(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10))
|
graph.draw_text(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10))
|
||||||
|
|
||||||
|
# Normally at the top of the loop, but because we're drawing the graph first, making it at the bottom
|
||||||
|
event, values = window.read()
|
||||||
|
|
||||||
|
if event in (sg.WIN_CLOSED, 'Exit'):
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
window.close()
|
window.close()
|
Loading…
Reference in New Issue