Python Forum
Syntax Error: Positional argument follows keyword argument
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax Error: Positional argument follows keyword argument
#1
Hello, I'm trying to design a GUI based code through Tkinter which include multiple choice questions that the user can click through radiobuttons. However when I try to run the code, I'm keep on getting a Syntax error starting that my positional arguments follow keyword argument.

This particular line seems to be where the error is orginating from.
Error:
r1=Radiobutton(root,text=User_answers[indexes[0]][0],value=0,variable=i,font="Times New Roman",12, bg="#E5E50E",fg="black",command=select)
I've proof checked my code numerous time & did search online however I did not obtain any results that are similar or close to the criteria that I am doing, hence I chose to come over here & enquire directly in hope of some guidance. If anyone can help me with the error and potentitally pin-point what I have done wrong, then I'd be very appreciative. Thanks Smile

import tkinter
import random
from tkinter import*



root=tkinter.Tk()
root.title("Anime Quiz")
root.geometry("1000x800")
root.config(background="#ffffff")
import random





#Questions=[
#   "Q1: "In what location does Portgaz D. Ace die in One Piece?",
#   "Q2) "What is the nationality of Jonathan Joestar in JoJo?",
#   "Q3) "In what background was Yuno originally born in Black Clover?",
#   "Q4) "True Or False? Ray is Isabella’s son in The Promised Neverland",
#   "Q5) "What was the name of the academy that Izuku Modorya attended in BNHA?",
#   "Q6) "How many Dragon Balls are there in total?",
#   "Q7) "In total: How many emperors are featured in One Piece?",
#   "Q8) "Why did Sasuke go to Orochimaru?",
#   "Q9) "Why did Eren turn evil in AOT?",
#   "Q10) "How many souls do you need to eat to become a demon weapon in Soul Eater?",
# ]

#User_answers=[
#    ["A)"Impel Down",B)"Dressrosa",C)"The Navy Headquarters",D)"Alabasta",],
#    ["A) "Japanese",B)"Italian",C)"Egyptian",D)"British",],
#    ["A) "Spade Kingdom",B)"Hage Village",C)"Golden Dawn Headquarters",)D)"Clover Kingdom",],
#    ["A) "True",B) "False")
#    ["A) "Kunugigaoka Junior High School",B)"U.A Highschool",C)"Kamome Academy",D)"Konoha Ninja Academy",],
#    ["A)"6",B)"8",C)"4",D)"7",],
#    ["A)"7",B)"2",C)"4",D)"32",],
#    ["A)"To team up with him",B)"To offer his body to Orochimaru",C)"To gain more power & murder his older brother, Itachi",D)"To revive the Uchiha clan"], 
#    ["A)"To murder Eldians",B)"To gain freedom",C)"To avenge her mother's death",D)"To conqeour Marley",],
#    ["A)"100",B)"90",C)"50",D)"70",],
# ]

Answers=[2,3,0,0,1,3,2,2,1,0]

User_answers=[]

indexes = []
def gen():
    global indexes
    while(len(indexes)<10):
        x = random.randint(0,14)
        if x in indexes:
            continue
        else:
            indexes.append(x)
  

def showresult(score):
     lablQuestion.destroy()
     r1.destroy()
     r2.destroy()
     r3.destroy()
     r4.destroy()
     
    
     global label, label1, label11
     label=Label(root,text="Your score is ",font=("Verdana",24),bg="#E5E50E",fg="black",justify="center")
     label.place(x=500,y=250)
     label1=Label(root,text=score,font=("Verdana", 24),bg="#E5E50E",fg="black",justify="center")
     label1.place(x=800,y=250)
                
     if score!=10:
         label11=Label(root,text="/10",font=("Verdana",24),bg="#E5E50E",fg="black",justify="center")
         label11.place(x=775,y=250)
     else:
         label11=Label(root,text="/10",font=("Verdana",24),bg="#E5E50E",fg="black",justify="center")
         label11.place(x=675,y=400)


def calculate():
    global indexes, User_answers, Answers
    x=0
    score=0
    for i in indexes:
        if User_answers[x]==answer[i]:
            score=score+1
        x+=1
        

    showresult(score)


ques=1

def select():
    global i,User_answers
    global lablQuestion,R1,R2,R3,R4,ques
    global ques
    x=i.get()
    User_answers.append(x)
    i.set(-1)

    if ques<10:
        lablQuestion.config(text=Questions[indexes[ques]])
        r1['text']=User_answers[indexes[ques]][0]
        r2['text']=User_answers[indexes[ques]][1]
        r3['text']=User_answers[indexes[ques]][2]
        r4['text']=User_answers[indexes[ques]][3]
        ques+=1
    else:
        calculate()
        
        

                                            
          
    
  

def Question():
    global lablQuestion,r1,r2,r3,r4,labelscore
    
    lablQuestion=Label(root,text=Questions[indexes[0]],font=("Agency FB",16),width=500,justify="center",wraplength=400,)
    lablQuestion.pack()
    

    img3=PhotoImage(file="C:/Users/Ramaz/OneDrive/Documents/Mustafa Quiz Code/103882 (1).png")
    
    labelimage3=Label(root,image=img3)
    labelimage3.pack(pady=5)
    global i,User_answers
    i=IntVar()
    i.set(-1)

    r1=Radiobutton(root,text=User_answers[indexes[0]][0],value=0,variable=i,font="Times New Roman",12,
                  bg="#E5E50E",fg="black",command=select)
    r1.pack(pady=5)

    r2=Radiobutton(root,text=User_answers[indexes[0]][1],value=1,variable=i,font=("Times New Roman",12,
                  bg="#E5E50E",fg="black",command=select)
    r2.pack(pady=5)

    r3=Radiobutton(root,text=User_answers[indexes[0]][2],value=2,variable=i,font=("Times New Roman",12)
                  bg="#E5E50E",fg="black",command=select) 
    r3.pack(pady=5)

    r4=Radiobutton(root,text=User_answers[indexes[0]][3],value=3,variable=i,font=("Times New Roman",12)
                   bg="#E5E50E",fg="black",command=select)
    r4.pack(pady=5)

    

    
    
def PressStart():
    labelimage.destroy()
    labeltext.destroy()
    lablInstruction.destroy()
    lablRules.destroy()
    btnStart.destroy()
    gen()
    Question()

img1=PhotoImage(file="C:/Users/Ramaz/OneDrive/Documents/Mustafa Quiz Code/b89597f8623c38e6e8b3f20afaad8522 (1).png")

labelimage=Label(root,image=img1,background="#ffffff")
labelimage.pack(pady=(40,0))
labeltext=Label(root,text="Anime Quiz",font=("Comic sans MS",24,"bold"))
labeltext.pack(pady=(0,50))


        
img2=PhotoImage(file="C:/Users/Ramaz/OneDrive/Documents/Mustafa Quiz Code/Frame.png")


            
btnStart=Button(root,image=img2,relief=FLAT,border=0,command=PressStart)
btnStart.pack()

lablInstruction=Label(root,text="Check Rules For Guidance And\nClick Start Once You Are ready",background="#ffffff",font=("Bembo",14),justify="center",)
lablInstruction.pack()

lablRules=Label(root,text="This quiz will consist of 6 questions relating to anime\nFor each question, you will only have 20 seconds to answer it\nOnce you have clicked a button, it will be your final choice\n Think wisely before selecting your answer",width=100,font=("Times New Roman", 14),background="#000000",foreground="#FF0000")
lablRules.pack()

root.mainloop()
Reply
#2
r1 = Radiobutton(
    root,
    text=User_answers[indexes[0]][0],
    value=0,
    variable=i,
    font=("Times New Roman", 12),
    bg="#E5E50E",
    fg="black",
    command=select,
)
The font name and the size must be in a sequence (Tuple).

The error came from the wrong interpretation, because of the missing parenthesis.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
(Feb-09-2021, 02:08 PM)DeaD_EyE Wrote:
r1 = Radiobutton(
    root,
    text=User_answers[indexes[0]][0],
    value=0,
    variable=i,
    font=("Times New Roman", 12),
    bg="#E5E50E",
    fg="black",
    command=select,
)
The font name and the size must be in a sequence (Tuple).

The error came from the wrong interpretation, because of the missing parenthesis.

Aha! So this was where I went wrong. I should've been a lot more courteous with my brackets, but the problem seems to have been sorted for now.

However when I run the code, I am now getting a different error message which states that:
Error:
File"C:\Users\Ramaz\OneDrive\Documents\Mustafa Work\Quiz code.py", line 124, in Question lablQuestion=Label(root,text=Question[indexes[0]],font=("Agency FB",16),width=500,justify="center",wraplength=400,) TypeError: 'function' object is not subscriptable


Any ideas on what part is now causing all this fuss?
Reply
#4
Using square brackets where you should use parentesis. Or is it using Question instead of Questions?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem passing argument to functionin inTkinter frame ericwm7248 3 1,018 Sep-11-2023, 03:11 PM
Last Post: deanhystad
Bug [PyQt] PyQt5 _translate not passing argument Lahearle 2 795 Jul-23-2023, 11:05 AM
Last Post: Axel_Erfurt
  [PyQt] QAction bold part of the string argument malonn 4 2,285 Sep-12-2022, 05:00 PM
Last Post: malonn
  how I can use the widgets as an argument of a function? pymn 9 2,100 Apr-26-2022, 09:23 PM
Last Post: deanhystad
  [Tkinter] Button 'command' Argument Confusion gw1500se 11 5,885 Nov-11-2021, 08:45 PM
Last Post: menator01
  [Kivy] Type error:takes 1 positional argument but 2 required hammer 3 2,670 Nov-09-2021, 06:01 AM
Last Post: deanhystad
  TypeError: isdeleted() argument 1 must be sip.simplewrapper, not PlotWidget Johna 2 3,776 Jan-22-2021, 05:34 PM
Last Post: deanhystad
  Usborne Coding for Beginners using Python 'Dodge the Bombs' Syntax Error CMSheWolfe 5 3,904 Jun-18-2020, 09:41 PM
Last Post: deanhystad
  [PyQt] how to pass tablewidget object like argument for function atlass218 2 2,266 Mar-02-2020, 06:53 AM
Last Post: atlass218
  Database Submit Entry Syntax Error Melford 27 7,740 Jan-27-2020, 04:20 PM
Last Post: Denni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020