Skip to content
View in the app

A better way to browse. Learn more.

Tip.It Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

D&D Die Roller - My most recent finished project

Featured Replies

I wrote a die rolling program in Python 3's tkinter library, mainly intended for D&D and other D20 systems.

Here is the code:

from tkinter import *

class RollTheDice:
   def __init__(self, parent):
       self.dieParent = parent
       self.dieContainer = Frame(parent).pack()

       self.dieLabel = Label(self.dieContainer, text="Number of Dice you will be rolling:")
       self.dieLabel.pack(side=TOP)

       self.dieEntry = Entry(self.dieContainer)
       self.dieEntry.pack(side=TOP)

       self.sideLabel = Label(self.dieContainer, text="Number of Sides per Die:")
       self.sideLabel.pack(side=TOP)

       self.sideEntry = Entry(self.dieContainer)
       self.sideEntry.pack(side=TOP)

       self.modLabel = Label(self.dieContainer, text="Number you will be adding to the roll (modifier):")
       self.modLabel.pack(side=TOP)

       self.modEntry = Entry(self.dieContainer)
       self.modEntry.pack(side=TOP)

       global rolldisp
       rolldisp = StringVar()
       self.rollResult = Label(self.dieContainer, textvariable=rolldisp)
       self.rollResult.pack(side=TOP)

       self.diceButton = Button(self.dieContainer)
       self.diceButton.configure(text="Roll the Dice!", background="green")
       self.diceButton.pack(side=LEFT)
       self.diceButton.bind("<Button-1>", self.diceButtonClick)
       self.diceButton.bind("<Return>", self.diceButtonClick)

       self.quitButton = Button(self.dieContainer)
       self.quitButton.configure(text="Quit", background="red")
       self.quitButton.pack(side=RIGHT)
       self.quitButton.bind("<Button-1>", self.quitButtonClick)
       self.quitButton.bind("<Return>", self.quitButtonClick)

   def diceButtonClick(self, event):
       die = int(self.dieEntry.get())
       side = int(self.sideEntry.get())
       mod = int(self.modEntry.get())
       DieRoll(die, side, mod)

   def quitButtonClick(self, event):
       self.dieParent.destroy()

def DieRoll(dice, sides, mods):
   import random
   rollnumber = 1
   runningtotal = 0
   endresult = ""
   while rollnumber <= dice:
       roll = random.randint(1, sides)
       endresult += "Roll #"
       endresult += str(rollnumber)
       endresult += ": "
       endresult += str(roll)
       endresult += "\n"
       runningtotal += roll
       rollnumber += 1
   total = runningtotal + mods
   finalresult = "Your Roll:\n"
   finalresult += endresult
   finalresult += "Total:"
   finalresult += str(total)
   rolldisp.set(finalresult)

root = Tk()
root.title("GUI Die Roller by MoosePasteInventor")
myapp = RollTheDice(root)
root.mainloop()

 

 

I'd love some feedback, so what do you think about my first real programming project?

Amazing NEW MoosePaste! The toothpaste made by, for, and from MOOSE! Order NOW! Call 1-800-55-MOOSE!

(side effects may include nausea and loss of appetite. restrictions apply, results may vary. no Moose are harmed in the making of MoosePaste. each sold separately, batteries not included. warning: does not exist)

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.