我只是通过Entry Box从用户输入中得到一个关于计算的快速问题 . 我很困惑为什么计算没有在标有“CCalc”的“def浓度”功能中执行 . 我想错误来自于代码无法从前一个函数获得用户输入“tbschk” . 还有什么我需要研究以确定如何正确地做到这一点?
import tkinter as tk
from tkinter import Label, Button, Entry
#multiply total brain by 1000ul
def tbscalc():
Bchk=float(BNum.get())
BCalc = (Bchk*1000)
tbsCalc["text"]=str(BCalc)
#divide concentration by total TBSul
def concentration():
Cchk=float(Conc.get())
tbschk=float(tbsCalc.get())
CCalc=(tbschk/Cchk)
PCalc["text"]=str(CCalc)
window=tk.Tk()
window.geometry("500x500")
#Using total brain to calculate TBS
BLabel=Label(window, text="Enter number of brains")
tbsLabel=Label(window, text="Amount of TBS needed in ul")
tbsCalc=Label(window)
BNum=Entry(window)
BTBSbtn=Button(window, text="Calculate", command=tbscalc)
#Using concentration to calculate total primary
CLabel=Label(window, text="Enter primary concentration")
PLabel=Label(window, text="This is how much primary antibody you need")
PCalc=Label(window)
Conc=Entry(window)
TPbtn=Button(window, text="Calculate", command=concentration)
#Locations
BLabel.grid(row=0 ,column=0)
BNum.grid(row=0 ,column=1)
tbsLabel.grid(row=1 ,column=0)
tbsCalc.grid(row=1 ,column=1)
BTBSbtn.grid(row=2 ,column=0)
CLabel.grid(row=3, column=0)
Conc.grid(row=3, column=1)
PLabel.grid(row=4, column=0)
PCalc.grid(row=4, column=1)
TPbtn.grid(row=5, column=0)
window.mainloop()
我收到错误消息:
Tkinter回调中的异常回溯(最近一次调用最后一次):文件“C:\ Users \ Kevin \ Anaconda3 \ lib \ tkinter__init __ . py”,第1699行,在调用中返回self.func(* args)文件“C:/ Users /Kevin/Desktop/Python/IHCprotocol.py“,第13行,浓度为tbschk = float(tbsCalc.get())AttributeError:'Label'对象没有属性'get'
它所指的错误
class CallWrapper:
"""Internal class. Stores function to call when some user
defined Tcl function is called e.g. after an event occurred."""
def __init__(self, func, subst, widget):
"""Store FUNC, SUBST and WIDGET as members."""
self.func = func
self.subst = subst
self.widget = widget
def __call__(self, *args):
"""Apply first function SUBST to arguments, than FUNC."""
try:
if self.subst:
args = self.subst(*args)
return self.func(*args)
except SystemExit:
raise
except:
self.widget._report_exception()
1 回答
你不能
get
显示的值label
这是错误告诉你的,解决我创建entry widget
名为e1
并没有在窗口中定位,以便我可以得到它的值 . 你的窗口看起来一样但现在能够得到结果显示 .