更改代码

时间:2015-10-05 18:54:33

标签: python string tkinter

所以,我一直在尝试运行这个程序,但每当我按下Enter键启动它(该部分工作正常)时它就会抛出这个错误:

ValueError: dictionary update sequence element #0 has length 1; 2 is required

这就是触发这一行的行:

words = ["Games","Development","Keyboard","Speed","Typer","Anything","Aplha","Zealous","Accurate","Basics","Shortcut","Purpose","Window","Counter","Fortress","Modification","Computer","Science","History","Football","Basketball","Solid","Phantom","Battlefield","Avdvanced","Warfare","Download","Upload","Antidisestablishmentarianism","Supercalifragilisticexpialidocious","Discomobobulation","Liberated","Assassin","Brotherhood","Revelation","Unity","Syndicate","Victory"]

def nextWord():
        global score
        entry.focus_set()
        if entry.get().lower() == words[1].lower():
            score += 1

        entry.delete(0, tkinter.END)
        random.shuffle(words)
        label.config(str(words[1]), text=str(words[0]))
        scoreLabel.config(text="Score: " + str(score))

我知道它可能在

(str(words[1])

部分是因为我在那里更改了一些代码以尝试修复另一个错误(我做了)。那么我有什么遗漏/错过了吗? 感谢。

1 个答案:

答案 0 :(得分:2)

config

label.config(text=str(words[0])) 只接受一个命名参数,但是你给它一个命名参数和一个位置参数。尝试:

Public Class speakers

    Dim currentq As Integer
    Dim Q1 As String = "Does sound play?"
    Dim Q2 As String = "Has the sound got too much bass or treble?"
    Dim Q3 As String = "Is the sound too loud or quiet?"
    Dim Q4 As String = "Is sound distorted?"
    Dim Q5 As String = ""
    Dim Q6 As String = ""
    Dim Q7 As String = ""
    Dim Q8 As String = ""

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If currentq = 0 Then
            Label1.Text = Q1
            currentq = 1
        ElseIf currentq = 1 Then
            Label1.Text = Q2
            currentq = 2
        ElseIf currentq = 2 Then
            Label1.Text = Q3
            currentq = 3
        ElseIf currentq = 3 Then
            Label1.Text = Q4
            currentq = 4
        ElseIf currentq = 4 Then
            Label1.Text = Q5
            currentq = 5
        ElseIf currentq = 5 Then
            Label1.Text = Q6
            currentq = 6
        ElseIf currentq = 6 Then
            Label1.Text =
            currentq = 7
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        currentq = currentq + 1
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Controls.Clear()
        InitializeComponent()
        Me.Hide()
        Form1.Show()
    End Sub

End Class