简体   繁体   English

如何在 PySimpleGUI 中美化结果

[英]How to prettify results in PySimpleGUI

I am currently practicing pandas我目前正在练习熊猫

I am using some pokemon data as a practice https://gist.github.com/armgilles/194bcff35001e7eb53a2a8b441e8b2c6我正在使用一些口袋妖怪数据作为练习https://gist.github.com/armgilles/194bcff35001e7eb53a2a8b441e8b2c6

i want to make a program that allows the user to input their queries and I will return the result that they need.我想制作一个程序,允许用户输入他们的查询,我将返回他们需要的结果。

i have a little problem where if i show the results of my pandas query in pysimplegui, it shows an ''ugly'' result unlike in the terminal that is ''pretty'.我有一个小问题,如果我在 pysimplegui 中显示我的 Pandas 查询的结果,它会显示一个“丑陋”的结果,这与终端中的“漂亮”不同。 To be more clear with my problem, here is an example.为了更清楚我的问题,这里有一个例子。

If I query this:如果我查询这个:

图片1

the result after i press "search" will be我按“搜索”后的结果将是

图片2

but if i look at the results in the terminal, it looks like this但是如果我在终端中查看结果,它看起来像这样

图3

here is my working code这是我的工作代码


import pandas as pd
import PySimpleGUI as sg

pd.set_option('display.max_rows', None)
df = pd.read_csv(r'PATH HERE')

layout = [  [sg.Text('This is a basic searcher \nPlease input your search parameters')],
            [sg.Text('Name'), sg.Input(key='Name')],
            [sg.Text('Type 1'), sg.Input(key='Type 1')],
            [sg.Text('Type 2'), sg.Input(key='Type 2')],
            [sg.Text('Total'), sg.Input(key='Total')],
            [sg.Text('Generation'), sg.Input(key='Generation')],
            [sg.Button('Search'), sg.Button('Close')]
]


window = sg.Window('Pokemon Database Query', layout).Finalize()


while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == 'Close':
        break
    if event == 'Search':
        df_query = 'df.loc['
        for key,value in values.items():
            if value != '':
                if value.isnumeric():
                    df_query += f'''(df['{key}'] == {value})&'''
                else:
                    df_query += f'''(df['{key}'] == '{value}')&'''
        df_query = df_query[:-1] + ']'
        sg.popup_scrolled('Result', eval(df_query))
window.close()

thank you谢谢你

The ugliness of the wrapping can be improved by specifying the window size to be returned.可以通过指定要返回的窗口大小来改善包装的丑陋程度。 size=(columns,rows)`大小=(列,行)`

sg.popup_scrolled('Result', eval(df_query), size=(100,40))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM