tkinter的控件Entry(python GUI )
摘要:tkinter是python GUI的标准库,本文介绍tkinter的Entry对象的使用。
00 Entry-文本框
from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
name=Label(win,text='Name')
password=Label(win,text='Password')
name.grid(row=0,column=0)
password.grid(row=1,column=0)
nameE=Entry(win)
passwordE=Entry(win)
nameE.grid(row=0,column=1)
passwordE.grid(row=1,column=1)
win.mainloop()
01 background和foreground的用法
from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
name=Label(win,text='Name')
password=Label(win,text='Password')
name.grid(row=0,column=0)
password.grid(row=1,column=0)
nameE=Entry(win,background='yellow')
passwordE=Entry(win,foreground='red')
nameE.grid(row=0,column=1)
passwordE.grid(row=1,column=1)
win.mainloop()
02 show的使用
from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
name=Label(win,text='Name')
password=Label(win,text='Password')
name.grid(row=0,column=0)
password.grid(row=1,column=0)
nameE=Entry(win)
passwordE=Entry(win,show='*')
nameE.grid(row=0,column=1)
passwordE.grid(row=1,column=1)
win.mainloop()
03 insert的使用
from tkinter import *
win=Tk()
win.title('leslie-wj')
win.geometry('500x200')
name=Label(win,text='Name')
password=Label(win,text='Password')
name.grid(row=0,column=0)
password.grid(row=1,column=0)
nameE=Entry(win)
passwordE=Entry(win)
nameE.insert(0,'leslie')
passwordE.insert(0,1990)
nameE.grid(row=0,column=1)
passwordE.grid(row=1,column=1)
win.mainloop()