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)
Asked
Active
Viewed 8,460 times
0

toyota Supra
- 3,181
- 4
- 15
- 19

lucifer
- 43
- 2
- 7
-
Possible duplicate of [How to create a message box with tkinter?](http://stackoverflow.com/questions/1052420/how-to-create-a-message-box-with-tkinter) – Hobbes Aug 09 '16 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)` – Hobbes Aug 09 '16 at 18:12
2 Answers
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"

James Bond
- 120
- 1
- 9
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)

Dorian Turba
- 3,260
- 3
- 23
- 67

noob
- 11
- 1
-
You're missing + right after a. Should be tk.messagebox.showinfo("info name", a+" "+b) – toyota Supra Feb 04 '23 at 01:50