FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PySimpleGUI/DemoPrograms/Demo_Bar_Chart.py at master · PySimpleGUI/PySimpleGUI · GitHub
PySimpleGUI
/
PySimpleGUI
Public
Notifications
You must be signed in to change notification settings
Fork
1.8k
Star
13.8k
Code
Issues
708
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PySimpleGUI
/
DemoPrograms
/
Demo_Bar_Chart.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (36 loc) · 1.93 KB
Breadcrumbs
PySimpleGUI
/
DemoPrograms
/
Demo_Bar_Chart.py
Copy path
File metadata and controls
57 lines (36 loc) · 1.93 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import
PySimpleGUI
as
sg
import
random
"""
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 2018-2026 PySimpleGUI. All rights reserved.
"""
BAR_WIDTH
=
50
# width of each bar
BAR_SPACING
=
75
# space between each bar
EDGE_OFFSET
=
3
# offset from the left edge for first bar
GRAPH_SIZE
=
DATA_SIZE
=
(
500
,
500
)
# size in pixels
sg
.
theme
(
'Light brown 1'
)
layout
=
[[
sg
.
Text
(
'Labelled Bar graphs using PySimpleGUI'
)],
[
sg
.
Graph
(
GRAPH_SIZE
, (
0
,
0
),
DATA_SIZE
,
k
=
'-GRAPH-'
)],
[
sg
.
Button
(
'OK'
),
sg
.
T
(
'Click to display more data'
),
sg
.
Exit
()]]
window
=
sg
.
Window
(
'Bar Graph'
,
layout
,
finalize
=
True
)
graph
=
window
[
'-GRAPH-'
]
# type: sg.Graph
while
True
:
graph
.
erase
()
for
i
in
range
(
7
):
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
=
'green'
)
# fill_color=sg.theme_button_color()[1])
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
()
if
event
in
(
sg
.
WIN_CLOSED
,
'Exit'
):
break
window
.
close
()
Back
|
FazBrowse Home
|
New Git URL