Home > Backend Development > Python Tutorial > Confused with message boxes

Confused with message boxes

WBOY
Release: 2024-02-09 21:10:04
forward
1096 people have browsed it

Confused with message boxes

Question content

I'm trying to make my program use tkinter's message box. So far it's working, but now I'm having trouble getting it to include a math equation in the title.

This is my code

while lives >= 0:
  x = random.randrange(1, 12)
  y = random.randrange(1, 12)
  name = numinput(x"*"y, "Answer:", minval=1, maxval=144)`
Copy after login

I also tried it

name = numinput("x"*"y", "Answer:", minval=1, maxval=144)

and

name = numinput(x*y, "Answer:", minval=1, maxval=144)

The first two it gives an error but the last one it gives the answer to my question but I want it to say something like (8*4)


Correct answer


The title is a string, but all your attempts are not strings.

use

name = numinput(f"{x} * {y}", "Answer:", minval=1, maxval=144)
Copy after login

The above is the detailed content of Confused with message boxes. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template