I am working on a simple Dice Roller for my D&D games and the code is working and everything, I just do not know how to make an output box for when the button is pressed. I want to press the button and have the randint output in the output box next to the button.
Asked
Active
Viewed 158 times
-2
-
1Don't post your code as an link to an image. Put the code as formatted text into the question itself. – Ted Klein Bergman Nov 30 '20 at 23:55
-
1You can edit your question by pressing the [edit](https://stackoverflow.com/posts/65082800/edit) button under your question. – Ted Klein Bergman Dec 01 '20 at 00:01
-
Most tkinter tutorials can answer this question for you. – Bryan Oakley Dec 01 '20 at 01:02
1 Answers
1
You can create an empty label right before/after your button.
result_label = Label(root, text = "")
result_label.grid(row = 0, column =1)
Then, you can update the text by adding the following inside your function :
result_label.config(text = randint(1,6))
This will replace the empty text of the label by a random number. If you want to keep the print output you'll have to save the value of randint(1,6) in a variable and use it as an input for both the text label and the print function.

Anthony D
- 11
- 3
-
1I appreciate your helping but your variable naming style is making me twitch. Python names should be lower_snake_case. Please read PEP8. – Novel Dec 01 '20 at 00:26
-
Variable naminge style corrected. Was not aware of PEP8. Thanks for the tip. – Anthony D Dec 01 '20 at 00:34