Home > OS >  Showing variable in a pop-up window
Showing variable in a pop-up window

Time:08-05

I have a small 2D game and I want to print a message when it's finished. The code is in Python and I used both Pygame and Tkinter for 2D graphic. When the game is finished it shows the message below:

messagebox.showinfo('Finish','Mouse ate all cheese slices.\nPolicies saved to file.')

I have a variable called steps and I need to show it in that window but it raise an error when I tried it like this:

messagebox.showinfo('Finish','Mouse ate all cheese slices after {steps}.\nPolicies saved to file.')

CodePudding user response:

You need to use an f string. Your code should look something like this:

messagebox.showinfo('Finish',f'Mouse ate all cheese slices after {steps}.\nPolicies saved to file.')

Here's a link to learn more ways to use this sort of formatting: Python F-Strings

CodePudding user response:

Try to use an f-string:

messagebox.showinfo('Finish',f'Mouse ate all cheese slices after {steps}.\nPolicies saved to file.')
  • Related