Advertisement
AyanUpadhaya

Create A Dice Simulator App in Python

Aug 4th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. # Python3
  2. # Dice Simulator app
  3. # Get image files : https://github.com/AyanUpadhaya/Dicesimulator
  4. # Watch live coding : https://www.youtube.com/watch?v=l-i38QC6ETA&t=475s&pp=sAQA
  5. # Follow me on Twitter: https://twitter.com/ayanupadhaya96
  6.  
  7. from tkinter import*
  8. from PIL import Image,ImageTk
  9. import random
  10.  
  11. root =Tk()
  12. root.title('Dice Simulator')
  13. root.geometry('400x400')
  14.  
  15. def change():
  16.     random_image= random.choice(image_list)
  17.     new_image= ImageTk.PhotoImage(Image.open(random_image))
  18.     image_label.configure(image=new_image)
  19.     image_label.image=new_image
  20.     root.update()
  21.  
  22. DEFAULT_IMAGE = 'images/die1.PNG'
  23. image_list=[
  24.     'images/die1.PNG',
  25.     'images/die2.PNG',
  26.     'images/die3.PNG',
  27.     'images/die4.PNG',
  28.     'images/die5.PNG',
  29.     'images/die6.PNG'
  30. ]
  31.  
  32.  
  33. my_image = ImageTk.PhotoImage(Image.open(DEFAULT_IMAGE))
  34.  
  35.  
  36. image_label= Label(root,image=my_image)
  37. image_label.pack(expand=True)
  38.  
  39. my_button = Button(root,text="Roll", width=20,height=3,fg='white',bg="#a4a6a6",font=10,command=change)
  40. my_button.pack(pady=20)
  41.  
  42.  
  43.  
  44. root.mainloop()
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement