简体   繁体   English

如何将计算出的值打印到消息框中?

[英]How to print a calculated value into a message box?

I am trying to print a calculated value, which is stored in "remainder" and print it into a message box.我正在尝试打印一个计算值,该值存储在“余数”中并将其打印到消息框中。 However, I am getting an error which states messagebox.showinfo('Alert','Current levels dropped by',remainder) TypeError: showinfo() takes from 0 to 2 positional arguments but 3 were given.但是,我收到一条错误消息,指出 messagebox.showinfo('Alert','Current levels drop by',remainder) TypeError: showinfo() 需要 0 到 2 个位置参数,但给出了 3 个。 I was wondering if anyone could help me out here, thank you so much.我想知道是否有人可以在这里帮助我,非常感谢。 The code is as shown below.代码如下所示。

quotient = c1/800
percent = quotient * 100
remainder = 100 - percent
alarmlight = my_canvas.create_oval(50, 50, 100, 100, fill='green')
my_canvas.itemconfig(alarmlight, fill="red") #Fill the circle with red
window = Tk()
window.eval('tk::PlaceWindow %s center' % window.winfo_toplevel()) #window will be infront of all windows
window.withdraw()
messagebox.showinfo('Alert','Current levels dropped by',remainder)

你最好的选择是使用f-strings

messagebox.showinfo('Alert',f'Current levels dropped by {remainder}')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM