制作一个Tkinter计算器,在一个区间内的给定点返回百分比

时间:2016-01-27 09:10:27

标签: python-2.7 tkinter

嗨我在运行此代码时遇到“浮动”对象无法调用错误。我正在使用python 2.7。

from __future__ import division
import sys
import math
sys.argv=["Main"]
import Tkinter
from Tkinter import *


def CalcRpmRatio():
    rpmMax = rpmMaxSet.get
    rpmMin = rpmMinSet.get
    rpmPoint = rpmPointSet.get
    newrpmMax = rpmMax() - rpmMin()
    result = rpmPoint() / newrpmMax()
    showResult = Label (mGui, text=str(ResultCount)+". "+str(result)).pack()
    global ResultCount
    ResultCount +=1

    return

ResultCount = 1
mGui = Tk()
mGui.geometry('400x150+200+200')
mGui.title('RPM To Percent Calc')
rpmMaxSet = DoubleVar()
rpmMinSet = DoubleVar()
rpmPointSet = DoubleVar()
rpmMaxSetLabel = Label(mGui, text='Max RPM').pack()
rpmMaxSetEntry = Entry(textvariable=rpmMaxSet) .pack()
rpmMinSetLabel = Label(mGui, text='Min RPM').pack()
rpmMinSetEntry = Entry(textvariable=rpmMinSet) .pack()
rpmMinPointLabel = Label(mGui, text='Point RPM').pack()
rpmPointSetEntry = Entry(textvariable=rpmPointSet) .pack()

mButton = Button(mGui, text='Calculate', command = CalcRpmRatio, fg = 'white', bg='black').pack()
mGui.mainloop()

我是python的新手,所以可能有一个明显的答案。

1 个答案:

答案 0 :(得分:1)

更新以下内容

rpmMax = rpmMaxSet.get()
rpmMin = rpmMinSet.get()
rpmPoint = rpmPointSet.get()
newrpmMax = rpmMax- rpmMin
result = rpmPoint / newrpmMax

这是我试过的编辑版本,它可以正常使用

from __future__ import division
import sys
import math
sys.argv=["Main"]
import Tkinter
from Tkinter import *


def CalcRpmRatio():
    rpmMax = rpmMaxSet.get()
    rpmMin = rpmMinSet.get()
    rpmPoint = rpmPointSet.get()
    newrpmMax = rpmMax- rpmMin
    result = rpmPoint / newrpmMax
    showResult = Label (mGui, text=str(ResultCount)+". "+str(result)).pack()
    global ResultCount
    ResultCount +=1

    return

ResultCount = 1
mGui = Tk()
mGui.geometry('400x150+200+200')
mGui.title('RPM To Percent Calc')
rpmMaxSet = DoubleVar()
rpmMinSet = DoubleVar()
rpmPointSet = DoubleVar()
rpmMaxSetLabel = Label(mGui, text='Max RPM').pack()
rpmMaxSetEntry = Entry(textvariable=rpmMaxSet) .pack()
rpmMinSetLabel = Label(mGui, text='Min RPM').pack()
rpmMinSetEntry = Entry(textvariable=rpmMinSet) .pack()
rpmMinPointLabel = Label(mGui, text='Point RPM').pack()
rpmPointSetEntry = Entry(textvariable=rpmPointSet) .pack()

mButton = Button(mGui, text='Calculate', command = CalcRpmRatio, fg = 'white', bg='black').pack()
mGui.mainloop()