烦!!! 发表于 2020-8-4 15:37:02

运行不起来

from tkinter import *


root = Tk()

Label = (root, text = "作品:").grid(row=0, column=0)‘=’赋值操作符总是报错
Label = (root, text = "作者:").grid(row=1, column=0)

e1 = Entry(root)
e2 = Entry(root)
e1.grid = grid(row=0, column=1, padx=10,pady=5)
e2.grid = grid(row=1, column=1, padx=10,pady=5)

def show:
    print('作品:《%s》~ '% e1.get())
    print('作品: %s~' % e2.get())

Button(root, text = '获取信息', width=10, command=show)\
             .grid(row=3,column=0, sticky=w, padx=10,pady=5)
Button(root, text = '退出',width=10,command=root.quit)\
             .grid(row=3 column=1, sticky=E, padx=10,pady=5)

mainloop()

zltzlt 发表于 2020-8-4 15:40:15

本帖最后由 zltzlt 于 2020-8-4 15:41 编辑

代码中有多处语法错误,帮你改好了:

from tkinter import *


root = Tk()

Label(root, text = "作品:").grid(row=0, column=0)
Label(root, text = "作者:").grid(row=1, column=0)

e1 = Entry(root)
e2 = Entry(root)
e1.grid(row=0, column=1, padx=10,pady=5)
e2.grid(row=1, column=1, padx=10,pady=5)

def show():
    print('作品:《%s》~ '% e1.get())
    print('作品: %s~' % e2.get())

Button(root, text = '获取信息', width=10, command=show).grid(row=3,column=0, sticky=W, padx=10,pady=5)
Button(root, text = '退出',width=10,command=root.quit).grid(row=3, column=1, sticky=E, padx=10,pady=5)

mainloop()
页: [1]
查看完整版本: 运行不起来