【Pyhon 3】: 170104:优品课堂: GUI -tkinter

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()

 

转载于:https://www.cnblogs.com/jinsky/p/6250411.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值