电压计算器-Python tkinter



英国

我想通过在文本框中检索数据来计算,但它给了我一个错误:

Traceback (most recent call last):
File "C:/Users/#####/Desktop/Python/Calculateur_U_R_I/App_main.py", line 43, in <module>
exe_button = Button(height=1, width=20, text='Exécuter', command=Calc())
File "C:/Users/#####/Desktop/Python/Calculateur_U_R_I/App_main.py", line 15, in Calc
result = text_label_1.get * text_label_2
TypeError: unsupported operand type(s) for *: 'method' and 'Text'
Process finished with exit code 1

代码是:

import tkinter
from tkinter import *
from tkinter import Text
help(tkinter.Text.get)
window = Tk()
window.minsize(1200, 400)
def Calc():
result = text_label_1.get * text_label_2
print(str(result))

text_label_1: Text = Text(window, height=1, width=10)
text_label_1.grid(row=0, column=2)
text_label_2 = Text(window, height=1, width=10)
text_label_2.grid(row=0, column=4)
name_label_1 = Label(window, height=1, width=10, text='Tension')
name_label_1.grid(row=0, column=0)
name_label_2 = Label(window, height=1, width=10, text=' = ')
name_label_2.grid(row=0, column=1)
name_label_3 = Label(window, height=1, width=10, text=' * ')
name_label_3.grid(row=0, column=3)
name_label_4 = Label(window, height=1, width=10, text=' = ')
name_label_4.grid(row=0, column=5)
name_label_5 = Label(window, height=1, width=10)
name_label_5.grid(row=0, column=6)
exe_button = Button(height=1, width=20, text='Exécuter', command=Calc())
exe_button.grid(row=1, column=5)
window.mainloop()

Ok but what is the index1 ? 


Traceback (most recent call last):
File "C:/Users/#####/Desktop/Python/Calculateur_U_R_I/App_main.py", line 47, in <module>
exe_button = Button(height=1, width=20, text='Exécuter', command=Calc())
File "C:/Users/#####/Desktop/Python/Calculateur_U_R_I/App_main.py", line 17, in Calc
r = int(text_label_1.get())
TypeError: get() missing 1 required positional argument: 'index1'

text_label_1.get * text_label_2-问题是text_label_1.get是一个方法(函数(,而text_label_2是一个Text。你需要从两个标签中获取文本,转换为数字并进行计算

相关内容

  • 没有找到相关文章

最新更新