美文网首页
简易老虎机程序

简易老虎机程序

作者: sunshaoping | 来源:发表于2018-08-04 10:38 被阅读0次
import tkinter
# 导入线程模块
import threading
import time
import random


root = tkinter.Tk()
root.title('fruits')
root.minsize(300, 300)

# 摆放按钮
btn1 = tkinter.Button(root, text='apple', bg='red')
btn1.place(x=20, y=20, width=50, height=50)

btn2 = tkinter.Button(root, text='pear', bg='white')
btn2.place(x=90, y=20, width=50, height=50)

btn3 = tkinter.Button(root, text='banana', bg='white')
btn3.place(x=160, y=20, width=50, height=50)

btn4 = tkinter.Button(root, text='orange', bg='white')
btn4.place(x=230, y=20, width=50, height=50)

btn5 = tkinter.Button(root, text='litchi', bg='white')
btn5.place(x=230, y=90, width=50, height=50)

btn6 = tkinter.Button(root, text='haw', bg='white')
btn6.place(x=230, y=160, width=50, height=50)

btn7 = tkinter.Button(root, text='cherry', bg='white')
btn7.place(x=230, y=230, width=50, height=50)

btn8 = tkinter.Button(root, text='peach', bg='white')
btn8.place(x=160, y=230, width=50, height=50)

btn9 = tkinter.Button(root, text='lemon', bg='white')
btn9.place(x=90, y=230, width=50, height=50)

btn10 = tkinter.Button(root, text='plum', bg='white')
btn10.place(x=20, y=230, width=50, height=50)

btn11 = tkinter.Button(root, text='grape', bg='white')
btn11.place(x=20, y=160, width=50, height=50)

btn12 = tkinter.Button(root, text='mango', bg='white')
btn12.place(x=20, y=90, width=50, height=50)

# 将所有选项组成列表
fruitlists = [btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn10, btn11, btn12]

# 是否开启循环的标志
isloop = False
stopsign = False
stopid = None


def round():
    print("开始运行...")
    global isloop

    global stopid
    # 判断是否开始循环
    if isloop == True:
        return

    # 初始化计数 变量
    i = 1
    if isinstance(stopid, int):
        i = stopid

    # 死循环
    while 1:

        # 延时操作
        time.sleep(0.2)
        # 将所有的组件背景变为白色
        for x in fruitlists:
            x['bg'] = 'white'

        # 将当前数值对应的组件变色
        fruitlists[i]['bg'] = 'blue'
        # 变量+1
        i += 1

        # 如果i大于最大索引直接归零
        if i >= len(fruitlists):
            i = 0
        if stopsign == True:
            isloop = False
            stopid = i

            break


# 建立一个新线程的函数
def newtask():
    global stopsign

    stopsign = False
    # 建立线程
    t = threading.Thread(target=round)
    # 开启线程运行
    t.start()


def stop1():
    global stopsign

    if stopsign == True:
        return
    stopsign = True


# 开始按钮

btn_start = tkinter.Button(root, text='start', command=newtask, bg='cyan')
btn_start.place(x=90, y=125, width=50, height=50)

# 停止按钮
btn_stop = tkinter.Button(root, text='end', command=stop1, bg='yellow')
btn_stop.place(x=160, y=125, width=50, height=50)

root.mainloop()

相关文章

  • 简易老虎机程序

  • Android简易老虎机的实现

    说起老虎机,玩过的人应该记得这种类型的图(这是主界面),下面就从最基本的知识分析整个APP的制作过程,也同时把An...

  • 微信小程序开发

    简易教程 · 小程序

  • 学习(90)

    1.民事诉讼司法程序包括:诉讼程序、非讼程序、执行程序。 2.诉讼程序包括:普通程序、简易程序(传统上的简易程序和...

  • 这样拉长审理期限,不合法

    按照刑事诉讼法的规定,刑事案件的审理有两种庭审模式:简易程序,普通程序。 简易程序审理的案件,期...

  • 手写服务器-3~测试网页

    用于测试服务器程序的简易网页

  • 小程序简易教程

    1、小程序简易教程 2、自己点开看

  • 初识slot游戏

    尽管很多人没有玩过老虎机游戏,但是大家或多或少都听说过老虎机游戏,或者说都被告知过,远离赌博,远离老虎机。那么老虎...

  • 小程序部署流程

    小程序部署流程: 一、 注册小程序(小程序接入指南) 二、创建小程序项目(简易教程·小程序) 三、部署开发环境(开...

  • Thompson抽样算法原理

    1、回顾多臂老虎机 在多臂老虎机中,我们通过探索加利用的方法,预测多臂老虎机的奖励分布。 我们将生活中的问题转化成...

网友评论

      本文标题:简易老虎机程序

      本文链接:https://www.haomeiwen.com/subject/zpbpvftx.html