我正在尝试简化我的程序,但它在“=”中表示“无效语法”
"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()
您不能在赋值周围放置括号,因为赋值不是表达式,它们不会计算任何值,也不会返回值。
>>> (x=1)
File "<stdin>", line 1
(x=1)
^
SyntaxError: invalid syntax