0

I am trying to display some value from variable in message box using Python for example following is my code and I have to display the values of a and b on message box so what should I do?

import tkinter as tk
a="hello"
b="how are you"
tk.messagebox.showinfo("info name",a,b)
2
  • Possible duplicate of How to create a message box with tkinter? Commented Aug 9, 2016 at 18:10
  • Just concatenate the variables and pass it into the second parameter of showinfo(). e.g. tk.messagebox.showinfo("info name", a + b) Commented Aug 9, 2016 at 18:12

2 Answers 2

4

To do what you want to do, combine a and b into one different variable.

c = a + " " + b

.showinfo() takes 2 arguments, so combine the two into one. The complete code would be:

import tkinter as tk
a = "hello"
b = "how are you"
c = a + " " + b
tk.messagebox.showinfo("info name", c)

Hope I helped! -Me!

EDIT: If you want to skip a line replace c = a + " " + b with c = a + "\n" + b

ANOTHER EDIT: If you need to use numbers, use "x" instead of regular x when x is the number. Example:

a = "2"
b = "3"
Sign up to request clarification or add additional context in comments.

2 Comments

Thanx it helped me
@shivleen Happy to help!
0

.showinfo() takes 2 arguments.

You can also use the following method to achieve the same result and avoid the creation of new variable.

import tkinter as tk
a = "hello"
b = "how are you"

tk.messagebox.showinfo("info name", a + " " + b)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.