Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

python - How to get Graphs and Table inside same frame one at time in PySimpleGUI?

I searched a lot but till i am not getting Graphs and Tables working in PySimpleGUI inside same frame.

What i achieved so far :

i have one dropdown menu where symbol of shares come. next to it is graph button and one table button. here different graph is comming.

What i want: what i want is a sigle frame below buttons where graph will come and inside same frame when i press table button table should be shown.

So i want single frame destroying every time and generating.

question from:https://stackoverflow.com/questions/65888815/how-to-get-graphs-and-table-inside-same-frame-one-at-time-in-pysimplegui

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Most of time, it's very difficult to understand what you mean by some simple sentences.

Maybe following example code OK for you,

enter image description here

import PySimpleGUI as sg

headings = ['President', 'Date of Birth']
data = [
    ['Ronald Reagan', 'February 6'],
    ['Abraham Lincoln', 'February 12'],
    ['George Washington', 'February 22'],
    ['Andrew Jackson', 'March 15'],
    ['Thomas Jefferson', 'April 13'],
]
width, height = 353, 100

sg.theme('DarkBlue')
sg.set_options(font=('Courier New', 12))

column_layout = [
    [sg.Table(data, headings=headings, pad=(0, 0), auto_size_columns=False,
        col_widths=(20, 15), num_rows=5, hide_vertical_scroll=True,
        justification='left', key='TABLE')],]

frame_layout = [
    [sg.Graph((width, height), (0, 0), (width, height), pad=(0, 0),
        background_color='green', key='GRAPH')],
    [sg.Column(column_layout, pad=(0, 0), visible=True, key='COLUMN',
        metadata=True)],]

layout = [
    [sg.Button('Frame Visible'), sg.Button('Table Visible')],
    [sg.Column(frame_layout, pad=(0, 0), key='FRAME', visible=True,
        metadata=True)],]

window  = sg.Window("Title", layout, size=(375, 265), finalize=True)
frame   = window['FRAME']
column  = window['COLUMN']

while True:

    event, values = window.read()

    if event == sg.WINDOW_CLOSED:
        break

    elif event == 'Frame Visible':
        visible = not frame.metadata
        frame.update(visible=visible)
        frame.metadata = visible

    elif event == 'Table Visible':
        if frame.metadata:
            visible = not column.metadata
            column.update(visible=visible)
            column.metadata = visible

window.close()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...