i am using tkinter to make my dice roller code look more appealing. i have gotten tkinter to display a roll button that works on the shell but in the same tkinter window it displays one value under roll and wonbt change that number when i click roll. how do i get it to change the number every time i click roll.
im stumped

import tkinter as tk import random die_1 = random. randint(1,6) die_2 = random. randint(1,6) total = float(die_1) + float(die_2) class Application(tk.Frame): def __init__(self, master=None): super().__init__(master) self.master = master self.pack() self.create_widgets() def create_widgets(self): self.button = tk.Button(self) self.button["text"] = "Roll" self.button["command"] = self.roll self.button.pack(side="top") self.result = tk.Label(self) self.result["text"] = total self.result.pack(side="bottom") def roll(self): die_1 = random. randint(1,6) die_2 = random. randint(1,6) total = float(die_1) + float(die_2) print(int(total)) root = tk.Tk() app = Application(master=root) app.mainloop()
Larz60+ write May-25-2023, 11:55 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I fixed your code this time. Please use BBCode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I fixed your code this time. Please use BBCode tags on future posts.