Python GUI 输入框的使用方法

python 弹出新窗口 python如何弹出输入框教程_登录界面

from tkinter import *


def printInfo():
    """打印输入的 用户名和密码"""
    print("Account:%s \npassword:%s" % (accountE.get(), pwdE.get()))
    accountE.delete(0, END)
    pwdE.delete(0, END)


# 1.创建对话框
root = Tk()
root.title("输入框的使用方法")

# 2.创建logo输入
msg = "欢迎登录界面"
sseGif = PhotoImage(file="timg.gif")
logo = Label(root, image=sseGif, text=msg, compound=BOTTOM)
logo.grid(row=0, column=0, columnspan=2, pady=10, padx=10)

# 3.创建用户标签与用户输入框
accountL = Label(root, text="Account")  # account标签
accountL.grid(row=1)

accountE = Entry(root)
accountE.insert(0, "Kevin")
accountE.grid(row=1, column=1)

# 4.创建密码标签与密码输入框
pwdL = Label(root, text="Password")  # pwd标签
pwdL.grid(row=2)

pwdE = Entry(root, show="*")
pwdE.insert(0, "password")
pwdE.grid(row=2, column=1, pady=10)

# 5.创建登陆与退出按钮
loginBtn = Button(root, text="Login", command=printInfo)
loginBtn.grid(row=3, column=0, sticky=W, pady=5)
quitBtn = Button(root, text="Quit", command=root.quit)
quitBtn.grid(row=3, column=1, sticky=W, pady=5)

root.mainloop()