GK SCIENTIST

General Knowledge One Stop Source
Menu
  • Home
  • Social Science
    • History
    • Political Science
    • Geography
  • Science
    • Physics
    • Chemistry
    • Biology
  • Chemistry Notes
  • Mathematics
  • Computer
  • Tutorial MySQL
  • Tutorial Python
  • Java Tutorial
  • English Grammar
  • English Essay
  • Indian Anthropology
  • Philosophy
  • Solved Paper
  • UPSC
  • Current Content
    • Current Affairs
    • RSTV News
    • Yojana and Kurukshetra Gist
  • Donate
  • Contact Us

If you are interested in advertising to our audience, submit the advertising enquiry form.

Advertising Enquiry
Computer

Python Dice Roll Simulator Project

Gk Scientist December 21, 2022 No Comments
Tweet WhatsApp Telegram

Python Dice Roll Simulator:

We can use the PyCharm code editor for this example. If you do not know about it then follow this link- How to install PyCharm for Python and create a program in it.

(1) Open the PyCharm code editor and create a new project in it. We named the project dice_roll_simulator.py. To build a Dice Roll Simulator in Python, we need to install some packages. For this open the terminal in PyCharm and install two packages i.e. tkinter and Pillow. You install all packages at the same time by simply typing in the terminal following command i.e. pip install tk Pillow and then press enter as shown below.

pip install tk pillow python - Python Dice Roll Simulator Project

Note: If the package shows an error while using in the code, you can simply install the package by clicking on the red bulb which appears below the error and you can directly install the package from here.

(4) Now add some images in the path where you have created the project as shown below.

dice roll images for python - Python Dice Roll Simulator Project

Download Images from Here: Dice Roll Project Images.

(3) Write the following code for creating Python Dice Roll Simulator Project as shown below.

Python Dice Roll Simulator Project Code 1 - Python Dice Roll Simulator Project
Python Dice Roll Simulator Project Code 2 - Python Dice Roll Simulator Project

Python Dice Roll Simulator Project Source Code:

import tkinter
from tkinter import *
from PIL import Image, ImageTk
import random

drs=Tk()
drs.title("Dice Roll Simulator")
drs.geometry("600x400")
drs.resizable(False,False)
drs.config(bg="#CCE3DE")

dice_img=["one.png","two.png","three.png","four.png","five.png","six.png"]
img1=ImageTk.PhotoImage(Image.open(random.choice(dice_img)))
img2=ImageTk.PhotoImage(Image.open(random.choice(dice_img)))

label1=tkinter.Label(drs,image=img1)
label2=tkinter.Label(drs,image=img2)

label1.image=img1
label2.image=img2

label1.place(x=40,y=100)
label2.place(x=340,y=100)

def dice_roll():
    img1 = ImageTk.PhotoImage(Image.open(random.choice(dice_img)))
    label1.config(image=img1)
    label1.image=img1

    img2 = ImageTk.PhotoImage(Image.open(random.choice(dice_img)))
    label2.config(image=img2)
    label2.image = img2

btn=tkinter.Button(drs,text="Dice Roll",bg="red",fg="white",font=("Merriweather",22,"bold"),command=dice_roll)
btn.place(x=240,y=0)

drs.mainloop()

(4) Now run the code and a window pop up, click on the Dice Roll button to roll your dice. The output window will be shown below.

Python Dice Roll Simulator Project Output Window - Python Dice Roll Simulator Project

Tutorial MySQL
Tutorial Python
Procedure-Oriented Programming
Modular Programming
Object-Oriented Programming (OOP)
C++ Character Set and Program Structure
FOR Loop in C Language
Python (programming language)– Wikipedia
Prev Article
Next Article

Related Articles

List Iteration in Python
List Iteration in Python: We can use the PyCharm code …
Gk Scientist November 27, 2022 Computer

List Iteration in Python

Logical Operators in Java
Logical Operators in Java: We can use the Eclipse IDE …
Gk Scientist January 1, 2023 Computer

Logical Operators in Java

Java for-each Loop
Java for-each Loop: We can use the Eclipse IDE for …
Gk Scientist January 6, 2023 Computer

Java for-each Loop

Copy Objects in Java
Copy Objects in Java: We can use the Eclipse IDE …
Gk Scientist January 9, 2023 Computer

Copy Objects in Java

Computer Network
What is Computer Network? Computers are generally used for the …
Gk Scientist October 8, 2022 Computer

Computer Network

How to Install PyCharm For Python on Windows
Install PyCharm For Python: (1) Many IDEs (Integrated Development Environment) …
Gk Scientist November 19, 2022 Computer

How to Install PyCharm For Python on Windows

Create RadioButton in Java
Create RadioButton in Java: We can use the Eclipse IDE …
Gk Scientist January 15, 2023 Computer

Create RadioButton in Java

Computer Software and Hardware
Computer Software and Hardware: What is Software? Software is an …
Gk Scientist August 2, 2022 Computer

Computer Software and Hardware

Leave a Reply Cancel Reply

Search




  • Popular
  • Recent




GK SCIENTIST

General Knowledge One Stop Source

Information

  • About Us
  • Terms and Condition, Disclaimer
  • Contact Us

Android Apps

  • IAS App For English Medium Students
  • IAS Basics App For English Medium Students
  • IAS Hindi App For Hindi Medium Students
DMCA.com Protection Status

Popular Tags

Biology (33) Biology Questions (88) Chemistry (57) Computer (211) Current Affairs (4) Current Content (0) Economy (10) English Essay (172) English Grammar (75) English Literature (10) Geography (83) History (259) Indian Anthropology (11) Indian Polity (14) JKAS Mains Question Papers (17) Mathematics (68) Moral Science (7) NCERT & Other Boards Books (25) Philosophy (114) Physics (89) Political Science (132) RS TV News (33) Science (553) Social Anthropology (7) Social Science (17) Solved Paper (47) UPSC (7) UPSC Mains Question Papers (26)

Downloads

  • NCERT Books
  • Old NCERT Books
  • NIOS Books For IAS, SSC, and State PSC Exam
  • Tamil Nadu Board Books: Important For UPSC, SSC, and State PSC Exam
  • Modern Indian and World History Notes For IAS Exam
  • UPSC Topper 2013 Gaurav Agrawal Notes For IAS Preparation
  • UPSC IAS Prelims General Studies – Previous Year Papers
  • UPSC Mains Question Papers

Copyright © 2023 GK SCIENTIST
Theme by MyThemeShop.com& Hosted On Cloudways
 

Loading Comments...