Python:Loop in Loop错误

问题描述 投票:-2回答:1

我正在尝试简化我的程序,但它在“=”中表示“无效语法”

"B=tkinter.Button(start, text=x)"

import tkinter
from tkinter import *
start = tkinter.Tk()
for x in ["New","Load"]:(
    B=tkinter.Button(start, text=x)
    B.pack()
    )
#N = tkinter.Button(start, text="New")
#L = tkinter.Button(start, text="Load")
#N.pack()
#L.pack()
start.mainloop()
python loops variables
1个回答
2
投票

您不能在赋值周围放置括号,因为赋值不是表达式,它们不会计算任何值,也不会返回值。

>>> (x=1)
  File "<stdin>", line 1
    (x=1)
      ^
SyntaxError: invalid syntax
© www.soinside.com 2019 - 2024. All rights reserved.