简体   繁体   中英

Tkinter: Output widget isn't displaying text

I'm relatively new when it comes to python and even more new when it comes to Tkinter, and I am making a Dice game program using GUIs and functions. At the end of the game, a new window pops up and displays some text with an output Widget that is meant to display the score, however, it doesn't appear. I believe I am using the right syntax, and there are no error messages when I run the program. Any answer would be appreciated.

Here is my code below:

'''

# SPICEY DICE Code snippet.
# - Create window
window2 = Tk()
window2.title("SPICEY DICE - Single Player Finish")
# - Label 1
Label(window2, text = "CONGRATULATIONS!").grid(row = 0, column = 0, sticky = W)
# - Label 2
Label(window2, text = "You have finished SPICEY DICE with a score of:").grid(row = 1, column = 0, sticky = W)
# - Text box 1
Output5 = Text(window2, width = 5, height = 1, wrap = WORD, background = "yellow")
Output5.grid(row = 2, column = 0, sticky = W)
# - Button 1
Button(window2, text = "LEADERBOARD", width = 15, command = SPLeaderboard).grid(row = 3, column = 0, sticky = W)
# - Label 3
Label(window2, text = "Close all of the windows to finish.").grid(row = 4, column = 0, sticky = W)
# - Run mainloop
window2.mainloop()

Output5.delete(0.0, END)
Output5.insert(END, str(TotalScore))

'''

The Output widget in question is 'Output5' and 'TotalScore' is the variable that is meant to be printed into it but doesn't appear.

Many Thanks.

I guess you need to write:

Output5.delete(0.0, END)
Output5.insert(END, str(TotalScore))

these codes between Tk() and mainloop .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM