简体   繁体   中英

Python: EasyGui printing variable to GUI

This may seem a silly question, but how do you print a variable on easygui?

Here is my code:

import easygui as eg
a = 4
eg.msgbox(msg='Hello World',a)

Error is:

SyntaxError: non-keyword arg after keyword arg

I know why I'm getting the error, because eg.codebox is expecting a title = "titleGoesHere"

Anyone know how to get a variable to show next to your string in easygui?

Many thanks.

If you want the contents of the variable a to be shown after Hello World , try this:

import easygui as eg
a = 4
eg.msgbox(msg='Hello World '+str(a))

In Python the + sign concatenates strings (so 'a'+'bc'='abc' ) but since a has an integer value, we call the function str which converts the 4 to a '4' so that the + will receive two strings :)

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