Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson17-diy1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
89b09d62
authored
Apr 30, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
0651e310
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
1 deletions
my_window.py
my_window.py
View file @
89b09d62
import
tkinter
import
tkinter
# 导入tkinter模块
def
register
():
# def定义register()函数
name
=
e1
.
get
()
# 用点记法,通过e1.get()获取用户名
password1
=
e2
.
get
()
# e2.get()获取密码
password2
=
e3
.
get
()
# e3.get()获取确认密码
print
(
"用户输入的信息为:"
,
name
,
password1
,
password2
)
# 打印出点击按钮的提示信息
# 建立窗口对象
root
=
tkinter
.
Tk
()
# Tk()类创建窗口
root
.
title
(
"注册"
)
# 设置窗口标题,注册
root
.
geometry
(
"400x320+500+300"
)
# 调用geometry()设置窗口大小400x320固定出现位置+500+30
root
.
resizable
(
width
=
False
,
height
=
False
)
# 使窗口无法拉伸,True可以拉伸,False不能拉伸
# 输入框entry并放置控件,bg支持英文和十六进制;light grey 浅灰色
e1
=
tkinter
.
Entry
(
root
,
show
=
None
,
font
=
(
'宋体'
,
14
),
bg
=
"light grey"
,
width
=
18
)
# ⬆调用tkinter模块Entry方法,参1窗口,参2显示为None,参3字体,参4bg背景填充色,参5文本框长度
e1
.
place
(
x
=
140
,
y
=
80
)
# 界面布局,调用place()方法设置x,y坐标140,80
# 密码输入框,密文形式
e2
=
tkinter
.
Entry
(
root
,
show
=
'*'
,
font
=
(
'宋体'
,
14
),
width
=
18
)
# ⬆调用tkinter模块Entry方法,参1窗口,参2显示为*,参3字体,参4文本框长度
e2
.
place
(
x
=
140
,
y
=
140
)
# 界面布局,调用place()方法设置x,y坐标140,140
e3
=
tkinter
.
Entry
(
root
,
show
=
'*'
,
font
=
(
'宋体'
,
14
),
width
=
18
)
# ⬆调用tkinter模块Entry方法,参1窗口,参2显示为*,参3字体,参4文本框长度
e3
.
place
(
x
=
140
,
y
=
200
)
# 界面布局,调用place()方法设置x,y坐标140,200
# 在图形界面上设定标签
lab
=
tkinter
.
Label
(
root
,
text
=
'您好!请填写注册信息'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
,
width
=
40
,
height
=
2
,
bg
=
"green"
)
# ⬆调用tkinter.label方法,参1窗口,参2窗口显示文本内容,参3字体,参4fg改变字体颜色
# ⬆参5设置文本宽度,参6设置文本高度,参7背景填充色
lab
.
place
(
x
=
0
,
y
=
0
)
# 界面布局,调用place()方法设置x,y坐标0,0
# 在输入框前展示文字标签: 用户名:、密 码:、确认密码:
lab1
=
tkinter
.
Label
(
root
,
text
=
'用户名:'
,
font
=
(
'宋体'
,
12
),
fg
=
"black"
)
lab1
.
place
(
x
=
60
,
y
=
80
)
lab2
=
tkinter
.
Label
(
root
,
text
=
'密 码:'
,
font
=
(
'宋体'
,
12
),
fg
=
"black"
)
lab2
.
place
(
x
=
60
,
y
=
140
)
lab3
=
tkinter
.
Label
(
root
,
text
=
'确认密码:'
,
font
=
(
'宋体'
,
12
),
fg
=
"black"
)
lab3
.
place
(
x
=
50
,
y
=
200
)
# 按钮;fg 字体颜色
button1
=
tkinter
.
Button
(
root
,
text
=
'提交'
,
bg
=
"lightgreen"
,
width
=
15
,
command
=
register
)
# ⬆调用tkinter.Button()方法,参1窗口,参2文本内容,参3背景填充色,参4文本高度
button1
.
place
(
x
=
150
,
y
=
250
)
# 界面布局,调用place()方法设置x,y坐标150,250
# 保持窗口监听,进入消息循环
root
.
mainloop
()
# mainloop()使窗口保持循环运行
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment