【Pyhon 3】: 170104:优品课堂: GUI -tkinter
生活随笔
收集整理的這篇文章主要介紹了
【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
總結
以上是生活随笔為你收集整理的【Pyhon 3】: 170104:优品课堂: GUI -tkinter的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: qq网名大全英文带符号
- 下一篇: 求一个美术作品展好听的名字!