简体   繁体   中英

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

I'm using a Warframe API to do a program that sees what, when, and where the Void Trader is selling items with PySimpleGUI. I think that my code's syntax is correct but when I run the program, it says that there are too many values, probably because the API is too big. Can someone help me?

This is my code:

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

It is caused by wrong arguments you passed to sg.Text .

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

For 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):

If you didn't use the keyword for each keyword arguments, then text will be 'When will it start?', size will be start in case

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

option size as a two-tuple (width, height) , but you just give it one string, so it got the exception,

ValueError: too many values to unpack (expected 2)

You can solve it by

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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