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
59201e61
authored
Jun 14, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
d3d6f098
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
my_window.py
my_window.py
View file @
59201e61
import
tkinter
# 导入tkinter
import
tkinter
# 导入tkinter
def
register
():
name
=
e1
.
get
()
# 用点记法.get()获取用户名
password1
=
e2
.
get
()
# 获取密码
password2
=
e3
.
get
()
# 获取确认密码
print
(
"用户输入的信息为:"
,
name
,
password1
,
password2
)
# 建立窗口对象
# 建立窗口对象
root
=
tkinter
.
Tk
()
# Tk()类创建窗口,并赋值给root
root
=
tkinter
.
Tk
()
# Tk()类创建窗口,并赋值给root
root
.
title
(
"注册"
)
# 设置窗口标题,(注册)
root
.
title
(
"注册"
)
# 设置窗口标题,(注册)
root
.
geometry
(
"400x320+500+200"
)
# 调用geometry()设置窗口大小400x320固定出现位置500+200
root
.
geometry
(
"400x320+500+200"
)
# 调用geometry()设置窗口大小400x320固定出现位置500+200
# 输入框entry并放置控件
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,140
# 在图形界面上设定标签
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
)
button1
.
place
(
x
=
150
,
y
=
250
)
# 界面布局,调用place()方法设置x,y坐标150,250
# 保持窗口监听,进入信息循环
# 保持窗口监听,进入信息循环
root
.
mainloop
()
# mainloop()使窗口保持循环
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