문제

I am using Python 2.7 and PyGObject 3.0. (This is VERY important! the PyGObject syntax changed with 3.0!)

I need to put a variable in place of a string in a markup, so the output is formatted. This is the code I have for formatting a standard string in a label.

lbl_tile1.set_markup('<span font_family="serif" font = "48" weight = "bold">W</span>')

However, I need to use the data in a variable. The following changes the text, but removes the formatting.

lbl_tile1.set_markup('<span font_family="serif" font = "48" weight = "bold">W</span>')
lbl_tile1.set_text(t[0])

I need to get the variable "t[0]" in place of "W" in the formatted string. How do I do this?

도움이 되었습니까?

해결책

You don't need use the set_text method. You can put the data on set_markup method.

For example:

lbl_tile1.set_markup('<span font_family="serif" font = "48" weight = "bold">{0}</span>'.format(t[0]))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top