"""
tkinter趣味颜色记忆游戏.py
"""
from tkinter import *
from tkinter import simpledialog
from tkinter import messagebox
def clickme():
global index
global score
s = simpledialog.askstring('版权所有','请输入颜色单词')
if s == cs[index]:
messagebox.showinfo('版权所有','回答正确,加10分')
score = score + 10
else:
messagebox.showinfo('版权所有','回答错误')
index = index + 1
if index < 10:
b.config(bg=cs[index]) # 配置下一个颜色
else:
messagebox.showinfo('版权所有','游戏结束!')
b.focus_force()
messagebox.showinfo('hello','欢迎来到趣味颜色记忆游戏')
messagebox.showinfo('hello','本游戏用Python开发,目的是为了学习tkinter可视化编程')
messagebox.showinfo('hello','接下来请单击红色按钮,然后在弹出的对话框中输入相应的颜色单词。')
index = 0
score = 0
cs = ['red','orange','yellow','green','cyan',
'blue','purple','pink','magenta','lime']
root = Tk()
b = Button(root,text='我是什么颜色的?',bg=cs[0],font=('',100,'normal'),command=clickme)
b.pack()
b.focus_force()
root.mainloop()
-
- 2026 年 3 月
- 2026 年 2 月
- 2026 年 1 月
- 2025 年 12 月
- 2025 年 11 月
- 2025 年 10 月
- 2025 年 9 月
- 2025 年 6 月
- 2025 年 5 月
- 2025 年 3 月
- 2025 年 2 月
- 2025 年 1 月
- 2024 年 12 月
- 2024 年 8 月
- 2024 年 6 月
- 2024 年 5 月
- 2024 年 4 月
- 2024 年 3 月
- 2024 年 2 月
- 2023 年 11 月
- 2023 年 9 月
- 2023 年 6 月
- 2023 年 5 月
- 2023 年 4 月
- 2023 年 3 月
- 2023 年 2 月
- 2023 年 1 月
- 2022 年 12 月
- 2022 年 11 月
- 2022 年 10 月
- 2022 年 9 月
- 2022 年 8 月
- 2022 年 7 月
- 2022 年 6 月
- 2022 年 5 月
- 2022 年 4 月
- 2022 年 3 月
- 2022 年 2 月
- 2022 年 1 月
- 2021 年 12 月
- 2021 年 11 月
- 2021 年 10 月
- 2021 年 9 月
- 2021 年 8 月
- 2021 年 7 月
- 2021 年 6 月
- 2021 年 5 月
- 2021 年 4 月
- 2021 年 3 月
- 2021 年 2 月
- 2021 年 1 月
- 2020 年 12 月
- 2020 年 11 月
- 2020 年 10 月
- 2020 年 9 月
- 2020 年 8 月
- 2020 年 7 月
- 2020 年 6 月
- 2020 年 5 月
- 2020 年 4 月
- 2020 年 3 月
- 2020 年 2 月
- 2020 年 1 月
- 2019 年 12 月
- 2019 年 11 月
- 2019 年 10 月
- 2019 年 9 月
- 2019 年 8 月
- 2019 年 7 月
- 2019 年 6 月
- 2019 年 5 月
- 2019 年 4 月
- 2019 年 3 月
- 2019 年 2 月
- 2018 年 3 月
- 2018 年 1 月
- 2017 年 9 月
- 2017 年 5 月
- 2017 年 1 月

