Python 可以将多个变量绑定到tkinter messagebox
我希望将多个变量绑定到tkinter messagebox中。这可能吗?我确实有一些我放在一起的示例代码,还有它的错误代码Python 可以将多个变量绑定到tkinter messagebox,python,user-interface,python-3.x,tkinter,Python,User Interface,Python 3.x,Tkinter,我希望将多个变量绑定到tkinter messagebox中。这可能吗?我确实有一些我放在一起的示例代码,还有它的错误代码 lines = ['Principal Amount: %s', 'Rate: %s', 'Time: %s years.', 'Compounded: %s times a year.'] % (principal, rate, time, compound) tkinter.messagebox.showinfo('Compound Interest R
lines = ['Principal Amount: %s', 'Rate: %s', 'Time: %s years.', 'Compounded: %s times a year.'] % (principal, rate, time, compound)
tkinter.messagebox.showinfo('Compound Interest Result:', "\n".join(lines))
它返回以下错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 1549, in __call__
return self.func(*args)
File "/Users/---/Documents/test.py", line 16, in compoundInterest
lines = ['Principal Amount: %s', 'Rate: %s', 'Time: %s years.', 'Compounded: %s times a year.'] % (principal, rate, time, compound)
TypeError: unsupported operand type(s) for %: 'list' and 'tuple'
不幸的是,通过研究,我还没有找到任何能够显示如何将变量正确绑定到MessageBox的东西,所以我不知道这仅仅是一种可能性。如果还有别的办法,我愿意听
(请注意,我不熟悉Python和tkinter)问题不在于messagebox,而在于错误消息中提到的行定义:
TypeError: unsupported operand type(s) for %: 'list' and 'tuple'
这项工作:
tkinter.messagebox.showinfo('Compound Interest Result:', "\n".join(["test1","test2","test3"]))
例如,要创建线,您可以执行以下操作:
sList=['Principal Amount: {}', 'Rate: {}', 'Time: {} years.', 'Compounded: {} times a year.']
valueList=['test1', 'test2','test3','test4']
lines = [s.format(value) for s,value in zip(sList,valueList)]
问题不在于messagebox,而在于错误消息中提到的行定义:
TypeError: unsupported operand type(s) for %: 'list' and 'tuple'
这项工作:
tkinter.messagebox.showinfo('Compound Interest Result:', "\n".join(["test1","test2","test3"]))
例如,要创建线,您可以执行以下操作:
sList=['Principal Amount: {}', 'Rate: {}', 'Time: {} years.', 'Compounded: {} times a year.']
valueList=['test1', 'test2','test3','test4']
lines = [s.format(value) for s,value in zip(sList,valueList)]
谢谢你,伙计!工作得很有魅力!谢谢你,伙计!工作得很有魅力!