Entry类,输入控件,用于显示简单的文本内容
- bg:输入框背景
- bd:边框大小
- cursor:光标形状
- font:文本字体
- width:文本框宽度
- fg:文字颜色
- justify:多行文本对齐方式
- relief:边框样式
- show:指定文本框内容显示为字符
- state:文本框状态,值为:normal、disabled
- textvariable:文本值
- exportselection:默认情况下,你如果在输入框中选中文本,默认会复制到粘贴板,如果要忽略这个功能,可设置 exportselection=0;实操没看到效果,不过我看好你哦
- highlightcolor:文本框高亮边框颜色
- selectforeground:选中文字的颜色
- selectborderwidth:选中文字背景边框宽度
- selectbackground:选中文字的背景颜色
- xscrollcommand:设置水平滚动条
诗 操 会 让 你 乐 趣 十 足 ......
一段登录代码,供参考...
import tkinter as tk
from tkinter import messagebox
window = tk.Tk()
window.title('这是一个登录窗口')
window.geometry('400x300')
# 定义一个用户栏标签
user_name = tk.Label(window, text='用户名:')
user_name.grid(row=0, sticky='w')
# 定义一个密码栏标签
password = tk.Label(window, text='密码:')
password.grid(row=1, sticky='w')
# 变量跟踪作用
user_ = tk.StringVar()
pwd_ = tk.StringVar()
# 设置两个文本框, grid是设置页面位置
entry_user = tk.Entry(window, show='', bg='white', highlightcolor='red', relief='raised',
textvariable=user_)
entry_user.grid(row=0, column=2, sticky='e')
entry_pwd = tk.Entry(window, show='*', highlightcolor='red', bg='white', xscrollcommand=2, relief='raised',
textvariable=pwd_)
entry_pwd.grid(row=1, column=2, sticky='e')
def login():
# 定义一个判断函数
account_name = entry_user.get()
account_password = entry_pwd.get()
if (account_name == 'account') and (account_password == '123456'):
# 登录成功输出成功提示
tk.messagebox.showinfo(title='successfully', message='登录成功')
else:
tk.messagebox.showerror(title='unsuccessfully', message='登录失败')
# 绑定按钮点击效果
login_button = tk.Button(window, text='登录', command=login).grid(row=2, column=2, sticky='w')
tk.mainloop()
:::state 输入框状态
值必须为:disabled, normal, readonly
:::selectforeground 选中文字的颜色
:::selectborderwidth 选中文字的背景边框宽度
:::selectbackground 选中文字的背景颜色
:::justify 显示多行文本的时候,设置不同行之间的对齐方式
值必须为:left, right, center
:::cursor 光标形状
:::relief 边框样式
值必须为:flat, groove, raised, ridge, solid, sunken
未完,待续...
一直都在努力,希望您也是!