【问题标题】:I am trying to display my outputs in the entry box widgets but nothing is showing upon execution yet no error我正在尝试在输入框小部件中显示我的输出,但执行时没有显示任何内容但没有错误
【发布时间】:2020-09-10 18:49:14
【问题描述】:

我认为我在从 ComputePayment 函数导入每月支付和总支付值时遇到了挑战。所以我想输入值: 贷款金额输入框 年利率输入框 年数利息箱 当我按下“计算付款”按钮时,答案会显示在每月付款和总付款的条目中。期待您的帮助,谢谢。 下面是我正在尝试运行的代码和图片,它是一个贷款计算器:

from tkinter import *
from PIL import ImageTk, Image
import db
from tkinter import messagebox
import show_client



class LoanCalculator:
    def __init__(self, data = ''):
        self.data = data
        print(self.data)
        self.win = Tk()
        #Reset The Window & Background Color
        canvas = Canvas(self.win, width=250, height=550, bg = "black")
        canvas.pack(expand=YES, fill=BOTH)

        #Show Window In The Center Of The Screen
        width = self.win.winfo_screenwidth()
        height = self.win.winfo_screenheight()

        x = int(width / 2 - 475 / 2)
        y = int(height / 2 - 400 / 2)

        str1 = "475x400+"+str(x)+"+"+ str(y)
        self.win.geometry(str1)
        self.win.resizable(width=False, height=False)
        #Change Icon
        self.win.iconbitmap("titico.ico")

        self.win.title("LOAN CALCULATOR | AJULES BACAS 1.0")

         #Change Icon
        self.win.iconbitmap("titico.ico")


    def add_frame(self):

        self.frame = Frame(self.win, height=375, width=450)
        self.frame.place(x = 12.5,y=12.5)

        x, y = 70, 20



        self.label = Label(self.frame, text="Please Enter The Loan Details Below:")
        self.label.config(font=('Ebrima', 14, 'bold'))
        self.label.place(x = 60, y = y + 55)

        #Enter Loan Interest Rate
        self.ir = Label(self.frame, text='Loan Annual Interest Rate')
        self.ir.config(font=('Ebrima', 12))
        self.ir.place(x = 5, y = 120)

        self.ir = Entry(self.frame, font='Ebrima 12', highlightbackground = "gold", highlightthickness = 1)
        self.ir.place(x=250, y = 120)

        #Enter Number of Years
        self.noy = Label(self.frame, text='Number of Years')
        self.noy.config(font=('Ebrima', 12))
        self.noy.place(x=5, y = 150)

        self.noy = Entry(self.frame, font='Ebrima 12', highlightbackground = "gold", highlightthickness = 1)
        self.noy.place(x=250, y = 150)

        #Enter Loan Amount
        self.ln = Label(self.frame, text='Loan Amount')
        self.ln.config(font=('Ebrima', 12))
        self.ln.place(x=5, y = 180)

        self.ln = Entry(self.frame, font='Ebrima 12', highlightbackground = "gold", highlightthickness = 1)
        self.ln.place(x=250, y = 180)


        #Monthly Payment
        self.monthlyPayment = Label(self.frame, text='The Monthly Payment Is:')
        self.monthlyPayment.config(font=('Ebrima', 12, 'bold'))
        self.monthlyPayment.place(x=5, y =  290)

        self.monthlyPaymentVar = StringVar()
        self.monthlyPayment = Entry(self.frame, font='Ebrima 12', textvariable = self.monthlyPaymentVar, highlightbackground = "gold", highlightthickness = 1)
        self.monthlyPayment.place(x=250, y = 290)

        #Total Payment
        self.totalPayment = Label(self.frame, text='The Total Payment Is:')
        self.totalPayment.config(font=('Ebrima', 12, 'bold'))
        self.totalPayment.place(x=5, y = 330)

        self.totalPaymentVar = StringVar()
        self.totalPayment = Entry(self.frame, font='Ebrima 12', textvariable=self.totalPaymentVar, highlightbackground = "gold", highlightthickness = 1)
        self.totalPayment.place(x=250, y = 330)

        self.button = Button(self.frame, text='COMPUTE PAYMENT', font='Ebrima 14 bold', fg = "gold", bg = "black", command=self.ComputePayment)
        self.button.place(x = 75, y =  230, width = 300, height = 40)

        return

    def ComputePayment(self):
        self.ir.get()
        self.noy.get()
        self.ln.get()

        ir = float(self.ir.get())
        noy = eval(self.noy.get())
        ln = float(self.ln.get())

        monthlyInterestRate = ir / 1200


        monthlyPayment = ln * monthlyInterestRate / (1 - 1 / (1 + monthlyInterestRate) ** (noy * 12))
        print(monthlyPayment)
        self.monthlyPaymentVar.set(format(monthlyPayment, '10.2f'))

        totalPayment = monthlyPayment * 12 * noy
        self.totalPaymentVar.set(format(totalPayment, '10.2f'))
        print(totalPayment)
        return 

enter image description here

【问题讨论】:

    标签: python-3.x string function tkinter tkinter-entry


    【解决方案1】:

    我认为你没有调用 add_frame 方法,所以这是错误的 而且我不知道您为什么要导入枕头,db,showclient,messagebox。即使没有它,它仍然可以运行。

    from tkinter import *
    from PIL import ImageTk, Image
    import db
    from tkinter import messagebox
    import show_client
    
    
    
    class LoanCalculator:
        def __init__(self, data = ''):
            self.data = data
            print(self.data)
            self.win = Tk()
            #Reset The Window & Background Color
            canvas = Canvas(self.win, width=250, height=550, bg = "black")
            canvas.pack(expand=YES, fill=BOTH)
    
            #Show Window In The Center Of The Screen
            width = self.win.winfo_screenwidth()
            height = self.win.winfo_screenheight()
    
            x = int(width / 2 - 475 / 2)
            y = int(height / 2 - 400 / 2)
    
            str1 = "475x400+"+str(x)+"+"+ str(y)
            self.win.geometry(str1)
            self.win.resizable(width=False, height=False)
            #Change Icon
            self.win.iconbitmap("titico.ico")
            self.add_frame()
    
            self.win.title("LOAN CALCULATOR | AJULES BACAS 1.0")
    
             #Change Icon
            self.win.iconbitmap("titico.ico")
    
    
        def add_frame(self):
    
            self.frame = Frame(self.win, height=375, width=450)
            self.frame.place(x = 12.5,y=12.5)
    
            x, y = 70, 20
    
    
    
            self.label = Label(self.frame, text="Please Enter The Loan Details Below:")
            self.label.config(font=('Ebrima', 14, 'bold'))
            self.label.place(x = 60, y = y + 55)
    
            #Enter Loan Interest Rate
            self.ir = Label(self.frame, text='Loan Annual Interest Rate')
            self.ir.config(font=('Ebrima', 12))
            self.ir.place(x = 5, y = 120)
    
            self.ir = Entry(self.frame, font='Ebrima 12', highlightbackground = "gold", highlightthickness = 1)
            self.ir.place(x=250, y = 120)
    
            #Enter Number of Years
            self.noy = Label(self.frame, text='Number of Years')
            self.noy.config(font=('Ebrima', 12))
            self.noy.place(x=5, y = 150)
    
            self.noy = Entry(self.frame, font='Ebrima 12', highlightbackground = "gold", highlightthickness = 1)
            self.noy.place(x=250, y = 150)
    
            #Enter Loan Amount
            self.ln = Label(self.frame, text='Loan Amount')
            self.ln.config(font=('Ebrima', 12))
            self.ln.place(x=5, y = 180)
    
            self.ln = Entry(self.frame, font='Ebrima 12', highlightbackground = "gold", highlightthickness = 1)
            self.ln.place(x=250, y = 180)
    
    
            #Monthly Payment
            self.monthlyPayment = Label(self.frame, text='The Monthly Payment Is:')
            self.monthlyPayment.config(font=('Ebrima', 12, 'bold'))
            self.monthlyPayment.place(x=5, y =  290)
    
            self.monthlyPaymentVar = StringVar()
            self.monthlyPayment = Entry(self.frame, font='Ebrima 12', textvariable = self.monthlyPaymentVar, highlightbackground = "gold", highlightthickness = 1)
            self.monthlyPayment.place(x=250, y = 290)
    
            #Total Payment
            self.totalPayment = Label(self.frame, text='The Total Payment Is:')
            self.totalPayment.config(font=('Ebrima', 12, 'bold'))
            self.totalPayment.place(x=5, y = 330)
    
            self.totalPaymentVar = StringVar()
            self.totalPayment = Entry(self.frame, font='Ebrima 12', textvariable=self.totalPaymentVar, highlightbackground = "gold", highlightthickness = 1)
            self.totalPayment.place(x=250, y = 330)
    
            self.button = Button(self.frame, text='COMPUTE PAYMENT', font='Ebrima 14 bold', fg = "gold", bg = "black", command=self.ComputePayment)
            self.button.place(x = 75, y =  230, width = 300, height = 40)
    
            return
    
        def ComputePayment(self):
            self.ir.get()
            self.noy.get()
            self.ln.get()
    
            ir = float(self.ir.get())
            noy = eval(self.noy.get())
            ln = float(self.ln.get())
    
            monthlyInterestRate = ir / 1200
    
    
            monthlyPayment = ln * monthlyInterestRate / (1 - 1 / (1 + monthlyInterestRate) ** (noy * 12))
            print(monthlyPayment)
            self.monthlyPaymentVar.set(format(monthlyPayment, '10.2f'))
    
            totalPayment = monthlyPayment * 12 * noy
            self.totalPaymentVar.set(format(totalPayment, '10.2f'))
            print(totalPayment)
            return 
    LoanCalculator()
    


    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      相关资源
      最近更新 更多