← 返回

python -猜字小游戏

代码运行效果如下:

注意:
1.必须要在python3环境想使用

2.QQ:3084276329(一起交流学习)

3.还请大家评论

Guess the word game代码如下:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Guess the word game
# 博客:https://www.cnblogs.com/muxii
# 那个木兮啊
import tkinter
import threading
import time
from tkinter import *
from tkinter import  messagebox
from tkinter import  messagebox

root = tkinter.Tk()
root.title('那个木兮啊-Guess the word')
root.minsize(300,330)

label =(root)
label = Label(root,text = '博客:https://www.cnblogs.com/muxii/\nQQ:3084276329\n—-————那个木兮啊——-———',font = ('微软雅黑',11),fg = 'red')
label.grid(row =0 ,column =0)
btn1 = tkinter.Button(root,text ='1',width = 5,height =2,bg='blue')
btn1.place(x=20,y=70)
btn2 = tkinter.Button(root,text = '2',width = 5,height =2,bg ='white')
btn2.place(x=90,y=70)
btn3 = tkinter.Button(root,text = '3',width = 5,height =2,bg ='white')
btn3.place(x=160,y=70)
btn4 = tkinter.Button(root,text = '3',width = 5,height =2,bg ='white')
btn4.place(x=230,y=140)
btn5 = tkinter.Button(root,text = '5',width = 5,height =2,bg ='white')
btn5.place(x=230,y=70)
btn6 = tkinter.Button(root,text = '6',width = 5,height =2,bg ='white')
btn6.place(x=230,y=210)
btn7 = tkinter.Button(root,text = '7',width = 5,height =2,bg ='white')
btn7.place(x=230,y=280 )
btn8 = tkinter.Button(root,text = '8',width = 5,height =2,bg ='white')
btn8.place(x=160,y=280)
btn9 = tkinter.Button(root,text = '9',width = 5,height =2,bg ='white')
btn9.place(x=90,y=280 )
btn10 = tkinter.Button(root,text = '10',width = 5,height =2,bg ='white')
btn10.place(x=20,y=280)
btn11 = tkinter.Button(root,text = '11',width = 5,height =2,bg ='white')
btn11.place(x=20,y=210)
btn12 = tkinter.Button(root,text = '12',width = 5,height =2,bg ='white')
btn12.place(x=20,y=140)
herolists = [btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn11]

isloop    = False

stopsing  = False
#定义停止id
stopid    = None

#定义函数,循环选项 设置背景颜色,选中的为红色,
def round():
    global isloop
    global stopid
    if isloop ==True:
        return
    i = 1
    #判断一个对象是否已经类型 type
    #考虑继承关系
    if isinstance(stopid,int):
        i = stopid

    while True:
        #
        time.sleep(0.05)#延时
        for x in herolists:
            x['bg'] = 'white'

        herolists[i]['bg'] ='blue'

        i += 1


        if i >= len(herolists):
            i = 0

        if  stopsing == True:
            isloop =False
            stopid = i
            break

 #停止
def stop1():

    global stopsing

    if stopsing == True:
        return
    stopsing = True

#开始
def newtask():
    global  isloop
    global  stopsing
    stopsing = False
#建立线程
    t = threading.Thread(target = round )
    t.start()
    isloop = True

btn_start = tkinter.Button(root,text = '开始',bg = 'red',command = newtask)
btn_start.place(x=90,y=175)
#
btn_stop = tkinter.Button(root,text = '结束',bg = 'yellow',command = stop1)
btn_stop.place(x=160,y=175 )

root.mainloop()
M

评论

还没有评论,来说第一句吧。

留下评论