Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python3
- # Dice Simulator app
- # Get image files : https://github.com/AyanUpadhaya/Dicesimulator
- # Watch live coding : https://www.youtube.com/watch?v=l-i38QC6ETA&t=475s&pp=sAQA
- # Follow me on Twitter: https://twitter.com/ayanupadhaya96
- from tkinter import*
- from PIL import Image,ImageTk
- import random
- root =Tk()
- root.title('Dice Simulator')
- root.geometry('400x400')
- def change():
- random_image= random.choice(image_list)
- new_image= ImageTk.PhotoImage(Image.open(random_image))
- image_label.configure(image=new_image)
- image_label.image=new_image
- root.update()
- DEFAULT_IMAGE = 'images/die1.PNG'
- image_list=[
- 'images/die1.PNG',
- 'images/die2.PNG',
- 'images/die3.PNG',
- 'images/die4.PNG',
- 'images/die5.PNG',
- 'images/die6.PNG'
- ]
- my_image = ImageTk.PhotoImage(Image.open(DEFAULT_IMAGE))
- image_label= Label(root,image=my_image)
- image_label.pack(expand=True)
- my_button = Button(root,text="Roll", width=20,height=3,fg='white',bg="#a4a6a6",font=10,command=change)
- my_button.pack(pady=20)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement