from tkinter import * root = Tk() root.title("BMS 图书管理系统") lbl = Label(root, text='书名:')#(1) lbl.pack() #(2) lbl.place(45.50) #(3) web 早期布局,, 常见。 lbl.grid(row=0, column=0) # web 早期布局,, 常见。 title = StringVar() # string 型的变量 title.set("书名") # entry = Entry(root,width=30) # entry.grid(row=0,column=1) 等价与下列代码。 Entry(root, width=30, textvariable=title).grid(row=0, column=1, sticky=W)Label(root, text="作者:").grid(row=1, column=0) author = StringVar()Entry(root, width=20, textvariable=author).grid(row=1, column=1, sticky=W)Label(root, text="价格:").grid(row=2, column=0) price = DoubleVar() price.set("0.0") Entry(root, width=20, textvariable=price).grid(row=2, column=1, sticky=W) Label(root, text="简介:").grid(row=3, column=0)# Entry(root, width=20).grid(row=2, column=1, sticky=W) txt_intro = Text(root, width=30, heigh=10) txt_intro.grid(row=3, column=1)Label(root, text="验证:").grid(row=4, column=0) is_valid = BooleanVar() Checkbutton(root, variable=is_valid).grid(row=4, column=1, sticky=W)def save_data():intro = txt_intro.get('1.0', END)print("*" * 50)print('书名:{}'.format(title.get()))print('作者:{}'.format(author.get()))print('定价:{}'.format(price.get()))print('简介:{}'.format(intro))print('验证:{}'.format(is_valid.get()))Button(root, text='保存', width=10, command=save_data).grid(row=5, column=1, sticky=W) # *** command=lambda: say_hello('xixi') 带参数的函数,需要用lambda 转一下啊。 Button(root, text='取消', width=10, command=lambda: root.quit()).grid(row=5, column=1, sticky=E) # Button(root, text='取消', width=10, command=root.quit).grid(row=5, column=1, sticky=E) root.mainloop()