import tkinter
import time
import threading
root.title('大转盘')
root.minsize(300,300)
btn1 = tkinter.Button(text = '奔驰',bg = 'red')
btn1.place(x = 20, y = 20, width = 50, height = 50)
btn2 = tkinter.Button(text = '宝马',bg = 'white')
btn2.place(x = 90, y = 20, width = 50, height = 50)
btn3 = tkinter.Button(text = '奥迪',bg = 'white')
btn3.place(x = 160, y = 20, width = 50, height = 50)
btn4 = tkinter.Button(text = '日产',bg = 'white')
btn4.place(x = 230, y = 20, width = 50, height = 50)
btn5 = tkinter.Button(text = '宾利',bg = 'white')
btn6.place(x = 230, y = 160, width = 50, height = 50)
btn7 = tkinter.Button(text = '奇瑞',bg = 'white')
btn7.place(x = 230, y = 230, width = 50, height = 50)
btn8 = tkinter.Button(text = '吉利',bg = 'white')
btn8.place(x = 160, y = 230, width = 50, height = 50)
btn9 = tkinter.Button(text = '大众',bg = 'white')
btn9.place(x = 90, y = 230, width = 50, height = 50)
btn10 = tkinter.Button(text = '沃尔沃',bg = 'white')
btn10.place(x = 20, y = 230, width = 50, height = 50)
btn11 = tkinter.Button(text = '红旗',bg = 'white')
btn11.place(x = 20, y = 160, width = 50, height = 50)
btn12 = tkinter.Button(text = '长城',bg = 'white')
btn12.place(x = 20, y = 90, width = 50, height = 50)
#将所有选项组成列表
carlist = [btn1,btn2,btn3,btn4,btn5,btn6,btn6,btn7,btn8,btn9,btn10,btn11,btn12]
#是否开始循环的标志
isloop = False
def round():
#判断是否开始循环
if isloop == True:
return
#初始化计数 变量
i = 0
#死循环
while True:
time.sleep(0.1)
#将所有的组件背景变为白色
for x in carlist:
x['bg'] = 'white'
#将当前数值对应的组件变色
carlist[i]['bg'] = 'red'
#变量+1
i += 1
#如果i大于最大索引直接归零
if i >= len(carlist):
i = 0
if functions ==True :
continue
else :
break
#建立一个新线程的函数。
def newtask():
global isloop
global functions
#建立新线程
t = threading.Thread(target= round)
#开启线程运行
t.start()
#设置程序开始标志
isloop = True
#是否运行的标志
functions = True
#定义停止循环的函数
def stop():
global isloop
global functions
functions = False
isloop = False
#开始按钮
btn_start = tkinter.Button(root,text = 'start',command = newtask)
btn_start.place(x = 90, y = 120, width = 50, height = 50)
btn_stop = tkinter.Button(root,text = 'stop',command = stop)
btn_stop.place(x = 160, y = 120, width = 50, height = 50)
root.mainloop()
import time
import threading
root.title('大转盘')
root.minsize(300,300)
btn1 = tkinter.Button(text = '奔驰',bg = 'red')
btn1.place(x = 20, y = 20, width = 50, height = 50)
btn2 = tkinter.Button(text = '宝马',bg = 'white')
btn2.place(x = 90, y = 20, width = 50, height = 50)
btn3 = tkinter.Button(text = '奥迪',bg = 'white')
btn3.place(x = 160, y = 20, width = 50, height = 50)
btn4 = tkinter.Button(text = '日产',bg = 'white')
btn4.place(x = 230, y = 20, width = 50, height = 50)
btn5 = tkinter.Button(text = '宾利',bg = 'white')
btn5.place(x = 230, y = 90, width = 50, height = 50)
btn6 = tkinter.Button(text = '劳斯',bg = 'white')btn6.place(x = 230, y = 160, width = 50, height = 50)
btn7 = tkinter.Button(text = '奇瑞',bg = 'white')
btn7.place(x = 230, y = 230, width = 50, height = 50)
btn8 = tkinter.Button(text = '吉利',bg = 'white')
btn8.place(x = 160, y = 230, width = 50, height = 50)
btn9 = tkinter.Button(text = '大众',bg = 'white')
btn9.place(x = 90, y = 230, width = 50, height = 50)
btn10 = tkinter.Button(text = '沃尔沃',bg = 'white')
btn10.place(x = 20, y = 230, width = 50, height = 50)
btn11 = tkinter.Button(text = '红旗',bg = 'white')
btn11.place(x = 20, y = 160, width = 50, height = 50)
btn12 = tkinter.Button(text = '长城',bg = 'white')
btn12.place(x = 20, y = 90, width = 50, height = 50)
#将所有选项组成列表
carlist = [btn1,btn2,btn3,btn4,btn5,btn6,btn6,btn7,btn8,btn9,btn10,btn11,btn12]
#是否开始循环的标志
isloop = False
def round():
#判断是否开始循环
if isloop == True:
return
#初始化计数 变量
i = 0
#死循环
while True:
time.sleep(0.1)
#将所有的组件背景变为白色
for x in carlist:
x['bg'] = 'white'
#将当前数值对应的组件变色
carlist[i]['bg'] = 'red'
#变量+1
i += 1
#如果i大于最大索引直接归零
if i >= len(carlist):
i = 0
if functions ==True :
continue
else :
break
#建立一个新线程的函数。
def newtask():
global isloop
global functions
#建立新线程
t = threading.Thread(target= round)
#开启线程运行
t.start()
#设置程序开始标志
isloop = True
#是否运行的标志
functions = True
#定义停止循环的函数
def stop():
global isloop
global functions
functions = False
isloop = False
#开始按钮
btn_start = tkinter.Button(root,text = 'start',command = newtask)
btn_start.place(x = 90, y = 120, width = 50, height = 50)
btn_stop = tkinter.Button(root,text = 'stop',command = stop)
btn_stop.place(x = 160, y = 120, width = 50, height = 50)
root.mainloop()