Horia.Muntean 0 Newbie Poster

this is the code of a "dice roller" I made
the output(result of print commands) shows in the terminal/cmd
is there a way to make a textbox that will show the results directly in tk?
eg. "You rolled 10 on the 1d12 dice!" #shown in a tk messagebox

and something else also.for example the dSixRoll() after it has taken a random value,can I use it for other operations?eg. theUsefulNumber = dSixRoll
it says dSixRoll is not defined(it's in a def block but I don't know how to extract it and use it for further operations)

from Tkinter import *
import random

#notes
master = Tk()
w = Label(master, text="Write a note")
w.pack()
        
e = Entry(master)
e.pack()

e.focus_set()

def callback():
    note = e.get()
    print "Note: " + note
    
b = Button(master, text="add note", width=10, command=callback)
b.pack()

class App:

    def __init__(self, master):
    	
    	
    	
    	w = Label(master, text="D&D Dice Roller")
        w.pack()
        b = Label(master, text="For GM use only")
        b.pack()

        frame = Frame(master)
        frame.pack()

        self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
        self.button.pack(side=RIGHT)

        self.dFour = Button(frame, text ="d4", command=self.dFour)
        self.dFour.pack(side=LEFT)
        
        self.dSix = Button(frame, text ="d6", command=self.dSix)
        self.dSix.pack(side=LEFT)

        self.dEight = Button(frame, text ="d8", command=self.dEight)
        self.dEight.pack(side=LEFT)
        
        self.dTen = Button(frame, text ="d10", command=self.dTen)
        self.dTen.pack(side=LEFT)
        
        self.dTwelve = Button(frame, text ="d12", command=self.dTwelve)
        self.dTwelve.pack(side=LEFT)
        
        self.dTwenty = Button(frame, text ="d20", command=self.dTwenty)
        self.dTwenty.pack(side=LEFT)
        
        self.dCent = Button(frame, text ="d100", command=self.dCent)
        self.dCent.pack(side=LEFT)



        
    def dFour(self):
        dFourRoll = random.randint(1, 4)
        dFourRoll = str(dFourRoll)
        print 'You rolled ' + dFourRoll + ' on the 1d4 dice!'
        
    def dSix(self):
        dSixRoll = random.randint(1, 6)
        dSixRoll = str(dSixRoll)
        print 'You rolled ' + dSixRoll + ' on the 1d6 dice!'
        
    def dEight(self):
        dEightRoll = random.randint(1, 8)
        dEightRoll = str(dEightRoll)
        print 'You rolled ' + dEightRoll + ' on the 1d8 dice!'
        
    def dTen(self):
        dTenRoll = random.randint(1, 10)
        dTenRoll = str(dTenRoll)
        print 'You rolled ' + dTenRoll + ' on the 1d10 dice!'
        
    def dTwelve(self):
        dTwelveRoll = random.randint(1, 12)
        dTwelveRoll = str(dTwelveRoll)
        print 'You rolled ' + dTwelveRoll + ' on the 1d12 dice!'
        
    def dTwenty(self):
        dTwentyRoll = random.randint(1, 20)
        dTwentyRoll = str(dTwentyRoll)
        print 'You rolled ' + dTwentyRoll + ' on the 1d20 dice!'
        
    def dCent(self):
        dCentRoll = random.randint(1, 100)
        dCentRoll = str(dCentRoll)
        print 'You rolled ' + dCentRoll + ' on the 1d100 dice!'



app = App(master)
mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.