Got a few of the Demos up to date with changes standard to many demos (edit me, get versions for example)

This commit is contained in:
PySimpleGUI 2022-06-11 09:01:27 -04:00
parent dba12e59f2
commit f1f60b03a1
5 changed files with 41 additions and 38 deletions

View file

@ -1,22 +1,21 @@
import PySimpleGUI as sg
import random
# Bars drawing in PySimpleGUI
#
# .--.
# | |
# .--.| |.--.
# | || || |
# | || || |
# | || || |
# .--.| || || |
# .--.| || || || |.--.
# | || || || || || |
# | || || || || || |
# .--.| || || || || || |.--.
# | || || || || || || || |.--.
# | || || || || || || || || |
# '--''--''--''--''--''--''--''--''--'
"""
Demo - Using a Graph Element to make Bar Charts
The Graph Element is very versatile. Because you can define your own
coordinate system, it makes producing graphs of many lines (bar, line, etc) very
straightforward.
In this Demo a "bar" is nothing more than a rectangle drawn in a Graph Element (draw_rectangle).
To make things a little more interesting, this is a barchart with that data values
placed as labels atop each bar, another Graph element method (draw_text)
Copyright 2022 PySimpleGUI
"""
BAR_WIDTH = 50 # width of each bar
@ -38,12 +37,13 @@ while True:
graph.erase()
for i in range(7):
graph_value = random.randint(0, GRAPH_SIZE[1])
graph_value = random.randint(0, GRAPH_SIZE[1]-25) # choose an int just short of the max value to give room for the label
graph.draw_rectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value),
bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0),
fill_color=sg.theme_button_color()[1])
fill_color='green')
# 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), font='_ 14')
# Normally at the top of the loop, but because we're drawing the graph first, making it at the bottom
event, values = window.read()