tkinter name lottery code example
Example: tkinter lottery app
#coding=utf-8import sysif sys.version_info [0] == 2: import tkinter from tkinter import *else: import tkinter as tkinter from tkinter import *import randomis_run=falsedef lottery_whirl (data, i, number): global is_run if i == 0: j=0 else: j=i%8 data [j-1] ["bg"]="#cccccc" data [j] ["bg"]="#00cd00" wait=[a for a in range (100, 300, 10)] + [b for b in range (300, 600, 300 //(number-28))] + \ [c for c in range (600, 1200, 120)] + [d for d in range (1200, 1800, 200)] if i<number: window.after (wait [i], lottery_whirl, data, i + 1, number) else: is_run=falsedef lottery_start (data): global is_run if is_run: return is_run=true for x in range (len (data)-1): data [x] ["bg"]="#cccccc" number=random.randint (30, 53) lottery_whirl (data, 0, number)def create_label (name, x, y): label=label (window, text=name, width=13, height=3, bg="#cccccc", font="Songti -18 bold") label.place (anchor=nw, x=x, y=y) return labelif __name__ == "__main__": window=tkinter.tk () window.geometry ("500x290 + 250 + 150") window.title ("Roulette Lottery") bg_label=label (window, width=80, height=24, bg="#ecf5ff") bg_label.place (anchor=nw, x=0, y=0) label1=create_label ("Wind Qingyang", 20, 20) label2=create_label ("Beggar", 180, 20) label3=create_label ("No Cliff", 340, 20) label4=create_label ("Western Poison", 20, 110) label5=create_label ("Dongxie", 340, 110) label6=create_label ("Sweeper", 20, 200) label7=create_label ("South Emperor", 180, 200) label8=create_label ("Zhang Sanfeng", 340, 200) data=[label1, label2, label3, label5, label8, label7, label6, label4] button_core=button (window, text="Start", command=lambda:lottery_start (data), width=130, height=53, bg="#00cd00", font="Songti -18 bold", bitmap="gray50", compound=tkinter.center) button_core.place (anchor=nw, x=180, y=110) window.mainloop ()