简体   繁体   English

Python“ Def”无效语法

[英]Python “Def” Invalid Syntax

I am kinda new to python and I only been learning it for about a week. 我是python的新手,我只学习了大约一个星期。 I am writing some script and I am using two def statements and it will say Invalid syntax fro the first def of the two defs 我正在编写一些脚本,并且正在使用两个def语句,它将说出两个def的第一个def的语法无效

Here is the code: 这是代码:

from tkinter import *
import tkinter.messagebox

master = Tk()
def continue():
    answer = tkinter.messagebox.askquestion('Error 408!', 'Something went wrong here. Click terminate to quit the app')
    if answer == 'Yes':
        quit()

dlabel = Label(text='Pick a Button').pack()
master.title('Uselessapp')
master.geometry('200x200')

button = Button(master, text="Play Game", command=continue)
button.pack()

mlabel = Label(text='--------').pack()

def quitapp():
    quit()

button = Button(master, text="Quit", command=quitapp)

button.pack()

mainloop()

Please help! 请帮忙!

您正在使用关键字作为函数名称,这是Python保留无法使用的名称.Python中有一个实际的关键字称为`` continue ''。您为函数使用了另一个名称,一个不是关键字的名称。

You have named your function continue which is a reserved word in python 您已将函数命名为continue ,这是python中的保留字

The following identifiers are used as reserved words, or keywords of the language, and cannot be used as ordinary identifiers. 以下标识符用作保留字或语言的关键字,不能用作普通标识符。

False      class      finally    is         return
None       continue   for        lambda     try
True       def        from       nonlocal   while
and        del        global     not        with
as         elif       if         or         yield
assert     else       import     pass
break      except     in         raise

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

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