I want to resolve the error "ValueError: too many values to unpack (expected 2)"

I want to resolve the error "ValueError: too many values to unpack (expected 2)"

我正在使用 Warframe API 编写一个程序,以查看 Void Trader 使用 PySimpleGUI 销售物品的内容、时间和地点。我认为我的代码语法是正确的,但是当我 运行 程序时,它说值太多,可能是因为 API 太大了。有人可以帮助我吗?

这是我的代码:

import requests
import PySimpleGUI as sg

r = requests.get('https://api.warframestat.us/pc')
void = r.json()['voidTrader']
start = void['startString']
end = void['endString']
location = void['location']

layout = [
[sg.Text('When will it start?', start)],
[sg.Text('When will it end?', end)],
[sg.Text('Where will it be?', location)]
]

window = sg.Window('Warframe Void Trader viewer', layout)

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break

这是由于您传递给 sg.Text 的错误参数造成的。

layout = [
    [sg.Text('When will it start?', start)],
    [sg.Text('When will it end?', end)],
    [sg.Text('Where will it be?', location)]
]

对于sg.Text.__init__,

def __init__(self, text='', size=(None, None), auto_size_text=None, click_submits=False, enable_events=False, relief=None, font=None, text_color=None, background_color=None, border_width=None, justification=None, pad=None, key=None, k=None, right_click_menu=None, grab=None, tooltip=None, visible=True, metadata=None):

如果您没有为每个关键字参数使用关键字,那么 text 将是 'When will it start?',size 将是 start,如果

sg.Text('When will it start?', start)

选项size作为一个二元组(width, height),但是你只给它一个字符串,所以它得到了异常,

ValueError: too many values to unpack (expected 2)

你可以通过

解决
sg.Text(' '.join(['When will it start?', str(start)]))