Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson20-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
c2092ddd
authored
Mar 30, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
d342feb7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
my_client.py
quiz.py
my_client.py
View file @
c2092ddd
...
@@ -27,9 +27,20 @@ class Note(): # 便签、笔记
...
@@ -27,9 +27,20 @@ class Note(): # 便签、笔记
self
.
but
.
place
(
x
=
240
,
y
=
305
)
self
.
but
.
place
(
x
=
240
,
y
=
305
)
# 展示所有的文字
# 展示所有的文字
self
.
y
=
20
self
.
y
=
20
self
.
val
=
0
# 单选框的value参数
self
.
v
=
IntVar
()
# 设置关联变量
for
info
in
alist
:
for
info
in
alist
:
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
font
=
(
"宋体"
,
11
),
anchor
=
W
,
fill
=
'#FF9900'
)
font
=
(
"宋体"
,
11
),
anchor
=
W
,
fill
=
'#FF9900'
)
#渲染代办事项的同时,将单选框组件也渲染
self
.
select
=
tkinter
.
Radiobutton
(
self
.
canvas
,
image
=
self
.
box
,
value
=
self
.
val
,
variable
=
self
.
v
,
width
=
25
,
height
=
15
,
borderwidth
=
0
)
#第一个参数:画布对象,二:加载方框图片
self
.
select
.
place
(
x
=-
20
,
y
=
self
.
y
-
10
)
#代码在for循坏里,每次在用过Radiobutton()方法后,让value对应的参数值增加1
#这样才能让每一个单选框组件设置一个不同的编号
self
.
val
+=
1
self
.
y
+=
30
self
.
y
+=
30
def
get_info
(
self
):
def
get_info
(
self
):
...
@@ -39,6 +50,11 @@ class Note(): # 便签、笔记
...
@@ -39,6 +50,11 @@ class Note(): # 便签、笔记
alist
.
append
(
info
)
alist
.
append
(
info
)
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
font
=
(
"宋体"
,
11
),
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
font
=
(
"宋体"
,
11
),
anchor
=
W
,
fill
=
'#FF9900'
)
anchor
=
W
,
fill
=
'#FF9900'
)
self
.
select
=
tkinter
.
Radiobutton
(
self
.
canvas
,
image
=
self
.
box
,
value
=
self
.
val
,
variable
=
self
.
v
,
width
=
25
,
height
=
15
,
borderwidth
=
0
)
self
.
select
.
place
(
x
=-
20
,
y
=
self
.
y
-
10
)
self
.
val
+=
1
self
.
y
+=
30
self
.
y
+=
30
...
...
quiz.py
View file @
c2092ddd
...
@@ -6,10 +6,14 @@ canvas = tkinter.Canvas(root, width=300, height=340, bg="lightblue")
...
@@ -6,10 +6,14 @@ canvas = tkinter.Canvas(root, width=300, height=340, bg="lightblue")
canvas
.
place
(
x
=
0
,
y
=
0
)
canvas
.
place
(
x
=
0
,
y
=
0
)
# ++++++++++++++++++++++++++++++++++++++++++++++++++++
# ++++++++++++++++++++++++++++++++++++++++++++++++++++
def
func
():
def
func
():
num
=
v
.
get
()
num
=
v
.
get
()
#获取选择的内容
print
(
"你选择了:"
,
num
)
print
(
"你选择了:"
,
num
)
v
=
tkinter
.
IntVar
()
v
=
tkinter
.
IntVar
()
#用radiobutton创建了四个单选组件
#value相当于给每个组件设置一个编号
#variable是tkinter.IntVar()生成的一个整数变量,
#四个都设一样,相当于关联在一起,这样四个选项只能选一个
rb1
=
tkinter
.
Radiobutton
(
root
,
text
=
'体育'
,
value
=
1
,
variable
=
v
,
command
=
func
)
rb1
=
tkinter
.
Radiobutton
(
root
,
text
=
'体育'
,
value
=
1
,
variable
=
v
,
command
=
func
)
rb2
=
tkinter
.
Radiobutton
(
root
,
text
=
'美术'
,
value
=
2
,
variable
=
v
,
command
=
func
)
rb2
=
tkinter
.
Radiobutton
(
root
,
text
=
'美术'
,
value
=
2
,
variable
=
v
,
command
=
func
)
rb3
=
tkinter
.
Radiobutton
(
root
,
text
=
'音乐'
,
value
=
3
,
variable
=
v
,
command
=
func
)
rb3
=
tkinter
.
Radiobutton
(
root
,
text
=
'音乐'
,
value
=
3
,
variable
=
v
,
command
=
func
)
...
...
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