python - GUI配额计算器
问题描述
我们是 python 新手,但正在创建自定义报价计算器,尽管单击计算后我们没有得到输出。代码如下。任何建议都是有帮助的。
'''
Barrington Advisory Solutions
BIS Development Team Project
'''
import tkinter
service = { #This is the dictionary that holds all of the services and their associated prices
'Mergers and Acquisitions':3000,
'Business Valuations':2000,
'Financial Analysis & Operational Ideas':5000,
'Strategic Planning Services':3500,
'Specialized Strategic Consultion Services':4000,
'Litigation Support':6000,
'': 0
}
services = [ #This is the list that holds all of the services (Used for the GUI output)
'',
'Mergers and Acquisitions',
'Business Valuations',
'Financial Analysis & Operational Ideas',
'Strategic Planning Services',
'Specialized Strategic Consultion Services',
'Litigation Support'
]
window = tkinter.Tk() #Creates the window (GUI)
class QuotaCalc:
## A class that asks for data about a client and then calculates
## both the time required for the service and the total estimate cost
def __init__(self, main, cust_name = 'none', co_size = 0, option1=None, option2=None, option3=None): ##This initializes the class with all of the variables that we will use
self.co_name = tkinter.Label(main, text = 'Customer/Company Name', font=('Arial Narrow', 20)).grid(row=20, column=1) #This displays text, the font is the font, and this tells the program what to display
self.co_name_input = tkinter.Entry(main).grid(row=20, column=3) #Allows user to input information #by putting both on row 0, it aligns the text
#can add in blank labels to space out the boxes (reduce the font to something small)
clicked = tkinter.StringVar() #initializing "clicked" as a string variable
clicked2 = tkinter.StringVar()
clicked3 = tkinter.StringVar()
clicked.set(services[0]) #Text to be displayed on the menu dropdown
clicked2.set(services[0])
clicked3.set(services[0])
timeRequired = 0
self.co_size = tkinter.Label(main, text = 'Company Size', font=('Arial Narrow', 20)).grid(row=40, column=1)
self.comp_size_input = tkinter.Entry(main).grid(row=40, column=3)
self.option_1 = tkinter.Label(main, text = 'Service 1 Needed', font=('Arial Narrow', 20)).grid(row=60, column=1)
self.drop = tkinter.OptionMenu( main , clicked , *service ).grid(row = 60, column = 3) #refers to the set number of services for dropdown
self.option_2 = tkinter.Label(main, text = 'Service 2 Needed', font=('Arial Narrow', 20)).grid(row=80, column=1)
self.drop2 = tkinter.OptionMenu( main , clicked2 , *service ).grid(row = 80, column = 3)
self.option_3 = tkinter.Label(main, text = 'Service 3 Needed', font=('Arial Narrow', 20)).grid(row=100, column=1)
self.drop3 = tkinter.OptionMenu( main , clicked3 , *service ).grid(row = 100, column = 3)
activated = True
self.bt = tkinter.Button(main, text='Calculate', command = self.myClick, fg = "purple", bg = "light blue").grid(row=120, column=2) ##fg is foreground (color), bg is background (color)
#Need to convert to when the button presses, it runs other functions of the class
time_req = tkinter.Label(window, text = 'Time Required', font=('Arial Narrow', 20)).grid(row=140, column=1)
total_cost = tkinter.Label(window, text = 'Price Quote', font=('Arial Narrow', 20)).grid(row=160, column=1)
#make a boolean to see if the button has been clicked and set it to false, when the boolean becomes true run the functions that do the math
def getTime(self, comp_size_input):
if self.comp_size_input == 0: #This determines how much time will be necessary based on the size of the company
self.timeRequired = 0
elif self.comp_size_input <= 20:
self.timeRequired = 1
elif self.comp_size_input <= 40:
self.timeRequired = 2
elif self.comp_size_input <= 60:
self.timeRequired = 3
elif self.comp_size_input <= 80:
self.timeRequired = 4
elif self.comp_size_input <= 100:
self.timeRequired = 5
elif self.comp_size_input <= 150:
self.timeRequired = 6
else:
self.timeRequired = 8
#return timeRequired
def calcCost(self): #This calculates the total cost of the services
cost = self.timeRequired * service[self.drop]
if self.option2 != '':
cost += self.timeRequired * service[self.drop2]
if self.option3 != '':
cost += self.timeRequired * service[self.drop3]
#return cost
def myClick(self):
timeRequired = self.getTime()
cost = self.calcCost
myLabel = tkinter.Label(window,text = cost)
myLabel.grid(row=140, column=3)
myLabel2 = tkinter.Label(window, text = timeRequired)
myLabel2.grid(row=160, column=3)
'''
if name == "main":
#calc = QuotaCalc(name, size, option1, option2, option3)
#timeRequired = calc.getTime()
#time_required = tkinter.Label(window, text = timeRequired, font=('Arial Narrow', 20)).grid(row=175, column=85) #print("Time rquired: ", str(timeRequired) + " month(s)")
#totalCost = calc.calcCost()
#totalCost = format(totalCost, '.2f')
#total_costs = tkinter.Label(window, text = 'Price Quote', font=('Arial Narrow', 20)).grid(row=200, column=85) #print("Price quote: $", totalCost)
'''
logo = tkinter.PhotoImage(file=r"C:\Users\micia\OneDrive\Desktop\Barrington.png")
##YOU MUST USE THE FILE PATH TO THE LOGO ON YOUR OWN COMPUTER
##THIS SHOWS MY PERSONAL FILE PATH
w1 = tkinter.Label(window, image=logo).grid(row=0, column = 2)
window.title('Barrington Advisory Quota Calculator') #Window Title
window.geometry('1000x500') #Sets the size of the window
#window.configure(bg='light blue') <- If we want to change the color of the background
e = QuotaCalc(window)
window.mainloop() #Tells the program to continue running until the GUI is closed
解决方案
cost = self.calcCost
-- 该行不调用该函数。它设置cost
为指向函数。你需要括号:cost = self.calcCost()
.
这是课堂作业吗?如果是这样,那很好,但如果您是专业人士,请扔进tkinter
垃圾桶。它一直是一个黑客。使用真正的 UI 库,例如 wxWidgets 或 Qt。
推荐阅读
- php - 数组内的函数引用到wordpress add_action,错误是类闭包的对象无法转换为字符串
- r - 匹配两个字符串中的字符序列
- wpf - 如何在不隐藏记录索引的情况下隐藏 XamDataGrid 的记录选择器箭头?
- php - PHP ajax加载结果和分页排序
- function - OBIEE 中的 MSUM 函数错误
- c# - C# 处理 Web 服务异常 401
- microservices - 本地开发环境的性能问题
- text-to-speech - 泰语单词的 TTS 阅读错误
- python - Textblob:按标签过滤单词
- machine-learning - 如何在将类数据(具有大量唯一值)输入机器学习模型之前对其进行预处理?