7tkinter笔记五
Posted zw~菜园子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了7tkinter笔记五相关的知识,希望对你有一定的参考价值。
Message and Entry组件
from tkinter import * msg = Message(text="Oh by the way, which one‘s Pink?") msg.config(bg=‘pink‘, font=(‘times‘, 16, ‘italic‘)) msg.pack(fill=X, expand=YES) mainloop()
from tkinter import * import sys def fetch(): print(‘Input => "%s"‘ % ent.get()) # get text def quit(): sys.exit() root = Tk() ent = Entry(root) ent.insert(0, ‘Type words here‘) # set text 插入一个原始默认的文本 ent.pack(side=TOP, fill=X) # grow horiz 获得水平增大 ent.focus() # save a click 保存单击事件 ent.bind(‘<Return>‘, (lambda event: fetch())) # on enter key 当按下回车键时触发 btn = Button(root, text=‘Fetch‘, command=fetch) # and on button 当按下按钮时触发 btn.pack(side=LEFT) btn1 = Button(root,text=‘QUIT‘,command=quit) btn1.pack(side=RIGHT) root.mainloop()
ent.insert(0, ‘some text‘) # set value 保存值 value = ent.get() # fetch value (a string) 获取值 ent.delete(0, END) # first, delete from start to end 清空值 ent.insert(0, ‘some text‘) # then set value 插入值
v
bc
用entry设计表单
from tkinter import * fields = ‘Name‘, ‘Job‘, ‘Pay‘ def fetch(entries): for entry in entries: print(‘Input => "%s"‘ % entry.get()) # get text def quit(): sys.exit() def makeform(root, fields): entries = [] for field in fields: row = Frame(root) # make a new row lab = Label(row, width=5, text=field) # add label, entry ent = Entry(row) row.pack(side=TOP, fill=X) # pack row on top lab.pack(side=LEFT) ent.pack(side=RIGHT, expand=YES, fill=X) # grow horizontal entries.append(ent) return entries if __name__ == ‘__main__‘: root = Tk() ents = makeform(root, fields) root.bind(‘<Return>‘, (lambda event: fetch(ents))) Button(root, text=‘Fetch‘,command= (lambda: fetch(ents))).pack(side=LEFT) Button(root,text=‘QUIT‘,command=quit).pack(side=RIGHT) root.mainloop()
以上是关于7tkinter笔记五的主要内容,如果未能解决你的问题,请参考以下文章
Android第一行代码学习笔记五---隐式Itent启动其它程序的活动
RabbitMQ学习笔记五:RabbitMQ之优先级消息队列
[原创]java WEB学习笔记61:Struts2学习之路--通用标签 property,uri,param,set,push,if-else,itertor,sort,date,a标签等(代码片段