耶~~~终於迈入第十天,完成了三分之一,今天要来讲文字方块,普遍常会看到的用法会在输入号密码的时候,但其实也可以用在很多地方,像是当成算运算式的工具,今天就会举这两个例子喔~
♠♣今天的文章大纲♥♦
参数 | 说明 |
---|---|
bg | 边框背景颜色 |
fg | 字型颜色 |
bd | 边框大小,预设为 2px |
cursor | 滑鼠形状设定 |
font | 字体 |
command | 按按钮时要用的函数或方法。 |
fg | 字型颜色 |
highlightcolor | 当按钮具有焦点时显示的颜色。 |
relief | 按钮边框的类型。有 SUNKEN、RAISED、GROOVE 和 RIDGE |
justify | 显示多个文本行时,LEFT 靠左对齐每一行; CENTER 使它们居中;或RIGHT 靠右对齐。 |
selectbackground | 被选取字串的背景颜色 |
selectborederwidth | 被选取字串的背景框宽度 |
selectforeground | 被选取字串的文字颜色 |
width | 按钮宽度 |
show | 指定文字框内容显示哪种字符,预设为 ’ * ’ |
state | 文字框状态,有两种为只能读取跟可修改,NORMAL、DISABLE,预设值为NORMAL |
textvariable | 文字框的值 |
xscrollcommand/yscrollcommand | 滚动条,X为水平的,Y为垂直的 |
command | 使用者更改内容时,此行会自动执行 |
方法 | 说明 |
---|---|
delete(first, last=None) | 删除文本框里的值,直接指定位置 |
get() | 获得文本框的值 |
icursor ( index ) | 边框大小,预设为 2px |
cursor | 滑鼠形状设定 |
font | 字体 |
command | 按按钮时要用的函数或方法。 |
fg | 字型颜色 |
highlightcolor | 当按钮具有焦点时显示的颜色。 |
relief | 按钮边框的类型。有 SUNKEN、RAISED、GROOVE 和 RIDGE |
justify | 显示多个文本行时,LEFT 靠左对齐每一行; CENTER 使它们居中;或RIGHT 靠右对齐。 |
selectbackground | 被选取字串的背景颜色 |
selectborederwidth | 被选取字串的背景框宽度 |
selectforeground | 被选取字串的文字颜色 |
width | 按钮宽度 |
show | 指定文字框内容显示哪种字符,预设为 ’ * ’ |
state | 文字框状态,有两种为只能读取跟可修改,NORMAL、DISABLE,预设值为NORMAL |
textvariable | 文字框的值 |
xscrollcommand/yscrollcommand | 滚动条,X为水平的,Y为垂直的 |
command | 使用者更改内容时,此行会自动执行 |
import tkinter as tk
root = tk.Tk()
root.geometry("350x400+200+300")
root.title('cuteluluWindow')
root.configure(bg="#7AFEC6")
root.iconbitmap('heart_green.ico')
root.geometry('300x300')
L1=tk.Label(root,text='Account',bg='#DDA0DD',fg="#8B008B",
font=("Algerian",15,"bold"),padx=9)
L2=tk.Label(root,text='Password',bg='#DDA0DD',fg="#8B008B",
font=("Algerian",15,"bold"))
L1.grid(row=1)
L2.grid(row=2)
E1=tk.Entry(root)
E2=tk.Entry(root,show="*")#设定用*遮住密码
E1.grid(row=1,column=1)
E2.grid(row=2,column=1)
root.mainloop()
执行结果⬇⬇⬇
import tkinter as tk
root=tk.Tk()
root.geometry("350x400+200+300")
root.title('cuteluluWindow')
root.configure(bg="#7AFEC6")
root.iconbitmap('heart_green.ico')
root.geometry('300x300')
def Info():
root1 = tk.Tk()
root1.title('cutelulu')
root1.configure(bg="#7AFEC6")
root1.iconbitmap('heart_green.ico')
root1.geometry('300x300')
if En.get()=='cutelulu' and En1.get()=='8888':#用get获得帐密去判断能不能登入
l=tk.Label(root1, text='Login successful!', bg="#7AFEC6",fg='#FFD306',
font=("Viner Hand ITC",15,"bold"),anchor='c',width=50,height=10)
l.pack()
else:
l=tk.Label(root1,text='Login Error!', bg="#7AFEC6",fg='#CE0000',
font=("Viner Hand ITC",15,"bold"),width=50,height=10,anchor='c')
l.pack()
label=tk.Label(root,text='Account',bg='#DDA0DD',fg="#8B008B",
font=("Algerian",15,"bold"),anchor='c')
label.grid(row=0)
En=tk.Entry(root)
En.grid(row=0,column=1)
label1=tk.Label(root,text='Password',bg='#DDA0DD',fg="#8B008B",
font=("Algerian",15,"bold"),anchor='c')
label1.grid(row=1)
En1=tk.Entry(root,show='*')#隐藏密码
En1.grid(row=1,column=1)
b=tk.Button(root,text='Exit',anchor='c',width=6,height=1,command=root.quit)#quit可以让pyhon shell结束
b.grid(row=2,column=0)
b1=tk.Button(root,text='Login',anchor='c',width=6,height=1,command=Info)
b1.grid(row=2,column=1)
root.mainloop()
执行结果⬇⬇⬇
输入帐号跟密码,这边预设帐号:cutelulu,密码:8888
输入成功介面
失败介面
import tkinter as tk
root=tk.Tk()
root.geometry("350x400+200+300")
root.title('cuteluluWindow')
root.configure(bg="#7AFEC6")
root.iconbitmap('heart_green.ico')
root.geometry('300x300')
def math():
out.configure(text = 'Answer: '+ str(eval(equ.get())))
label =tk.Label(root, text="Enter your math question:",bg="#7AFEC6",fg='#FFAAD5',font=("Ravie",10,"bold"))
label.pack()
equ = tk.Entry(root)#输入要算的东西
equ.pack()
out = tk.Label(root,bg="#7AFEC6",fg='#FF5151',font=("Ravie",15,"bold"))#储存计算结果
out.pack()
btn = tk.Button(root,text="count",command=math)#执行钮
btn.pack()
root.mainloop()
执行结果⬇⬇⬇
输入想要算的运算式
结果会回传到介面中
以上是今天的Entry()方法,终於到第十天了,算是一个关卡,代表再二十天就可以完成这个任务了,
耶~~~
谢谢大家愿意看我的文章,有问题都可以留言讨论喔~~~
<<: [Day24] Tableau 轻松学 - TabPy 使用方法 1
tags: OC 30 day 记忆体泄漏 指的是一个对象的记忆体没有被即时回收,在该回收的时候没有...
今天来介绍Odoo studio,对於程序苦手或非程序人员,运用Odoo studio可以直接透过见...
前言 走过了资料分析、演算法选择後, 我们得知了有些可以改善模型的方向: 解决资料不平衡 学习率的设...
铁人赛终於来到尾声... 再也不用担心忘记发文了!! Sport vector created by...
Case01 与 Day23 范例的差异,就是把 js fetch 的语法 extract 成 fu...