slotmachine.py - from tkinter import from tkinter import...

This preview shows page 1 - 2 out of 2 pages.

from tkinter import * from tkinter import messagebox import random as r import time as t ## SETUP ## app = Tk() app.title("Slot Machine") app['bg'] = "gold" ## GRID PADDING ## app.rowconfigure(1,pad=10) app.rowconfigure(2,pad=10) app.rowconfigure(3,pad=10) app.rowconfigure(4,pad=10) app.columnconfigure(1,pad=30) app.columnconfigure(2,pad=30) app.columnconfigure(3,pad=30) money=100 ## DEFS (One for each button) ## def spin(): global money #look for money out of def leverButton.grid_remove() resultLabel.grid_remove() money-=10 #update money label moneyLabel['text']="$%.d"%(money) #spin slots #spin all 3 for times in range(1,31): s1=r.randint(1,7) s2=r.randint(1,7) s3=r.randint(1,7) #put 3 random images into PhotoImages imgs1['file'] ="pic%d.gif"%(s1) imgs2['file']="pic%d.gif"%(s2) imgs3['file'] ="pic%d.gif"%(s3) t.sleep(0.03)#pause for 3 percent of a second app.update_idletasks() #spin only 2 and 3 for times in range(1,31): s2=r.randint(1,7) s3=r.randint(1,7) #put 3 random images into PhotoImages imgs2['file']="pic%d.gif"%(s2) imgs3['file'] ="pic%d.gif"%(s3) t.sleep(0.03)#pause for 3 percent of a second app.update_idletasks() #spin only 3

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture