#๐Ÿ”’ Need help on displaying text for CustomTkinter.

4 messages ยท Page 1 of 1 (latest)

old oriole
#

Hello, I'm new to coding, and i'm trying to code a button that rolls a dice on the click of a button. But everytime i click the button, instead of it replacing the initial roll, it creates new text underneath it. I'm not sure what i'm doing wrong and i need help haha.

Here is my code:

import customtkinter as ctk
import random

def button_callbck():
dice = random.randint(1, 6)
if dice in (1,2,3,4,5,6):
label = ctk.CTkLabel(Tapp, text = ("You rolled a " + str(dice) + "!"))
label.pack( pady=55)

Tapp = ctk.CTk()
Tapp.title("Roll the dice")

button = ctk.CTkButton(Tapp, text="Roll the dice.", command=button_callbck)
button.pack(padx=20, pady=50)

Tapp.mainloop()

gritty blazeBOT
#

@old oriole

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

gritty blazeBOT
#

@old oriole

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.