Class 在使用pyknow开发基于知识的系统时,如何调用要由tkinter按钮执行的类对象
我目前正在使用pyknow库做一个基于基本知识的系统,我想为它创建一个用户界面;我用tkinter做得很好。唯一的问题是试图通过按钮获取要调用的类方法,以便从输入字段获取结果并将其插入列表框: 下面是我在GUI运行良好的情况下尝试实现的代码部分: 代码如下:Class 在使用pyknow开发基于知识的系统时,如何调用要由tkinter按钮执行的类对象,class,button,tkinter,pycharm,Class,Button,Tkinter,Pycharm,我目前正在使用pyknow库做一个基于基本知识的系统,我想为它创建一个用户界面;我用tkinter做得很好。唯一的问题是试图通过按钮获取要调用的类方法,以便从输入字段获取结果并将其插入列表框: 下面是我在GUI运行良好的情况下尝试实现的代码部分: 代码如下: import tkinter as tk from tkinter import * from random import choice from pyknow import * class Kbsgui: def
import tkinter as tk
from tkinter import *
from random import choice
from pyknow import *
class Kbsgui:
def __init__(self, window):
self.l1 = Label(window, text="1. What is the self assessment status for that particular year? (0 - missing, 1 - present) ")
self.l1.grid(row=0, column=0)
self.l2 = Label(window, text="2. Are there self assessments existing betwwen 1992 - 2014? (yes/no) ")
self.l2.grid(row=1, column=0)
self.l3 = Label(window, text="3. Are there Credit balances for successive years? (yes/no) ")
self.l3.grid(row=2, column=0)
self.l4 = Label(window, text="4. Are there debit balances for successive years? (yes/no) ")
self.l4.grid(row=3, column=0)
# define entries
self.self_ass_status = tk.Entry()
self.e1 = Entry(window, textvariable=self.self_ass_status)
self.e1.grid(row=0, column=1)
self.self_ass_captured = tk.Entry()
self.e2 = Entry(window, textvariable=self.self_ass_captured)
self.e2.grid(row=1, column=1)
self.credit_bal_status = tk.Entry()
self.e3 = Entry(window, textvariable=self.credit_bal_status)
self.e3.grid(row=2, column=1)
self.debit_bal_status = tk.Entry()
self.e4 = Entry(window, textvariable=self.debit_bal_status)
self.e4.grid(row=3, column=1)
#create window object
window = Tk()
window.title("RPA-KBS APP")
kg = Kbsgui(window)
#-----Beginning of KBS Class----
class Ledger_errors(Fact):
pass
class LedgerErrorsInferenceEngine(KnowledgeEngine):
def returns_missing(self):
print('\n The returns for the year(s) is uncaptured. ')
@Rule(AND(Ledger_errors(self_assessment_status='0'),
Ledger_errors(self_assessments_captured='yes')
)
)
def credit_balances(self):
print('\n Uncaptured losses for preceding years. ')
print('\n')
@Rule(AND(Ledger_errors(debit_balances_status='yes'),
Ledger_errors(self_assessments_captured='yes')
)
)
def erroneous_balances(self):
print(' \n credits not carried forward to successive years. ')
print('\n')
@Rule(AND(Ledger_errors(credit_balances_status='yes'),
Ledger_errors(self_assessments_captured='yes')
)
)
def undefined_errors(self):
print('\n')
def display_results():
for i in range(1):
print('\n')
try:
self_assessment_status = int(kg.self_ass_status.get())
self_assessments_captured = str(kg.self_ass_captured.get())
credit_balances_status = str(kg.credit_bal_status.get())
debit_balances_status = str(kg.debit_bal_status.get())
engine = LedgerErrorsInferenceEngine()
engine.reset()
engine.declare(Ledger_errors(self_assessment_status=choice([self_assessment_status]),self_assessments_captured=choice([self_assessments_captured]),
credit_balances_status=choice([credit_balances_status]), debit_balances_status=choice([debit_balances_status])))
engine.run()
except ValueError:
pass
#-----End of KBS Class----
def __call__(self):
le = LedgerErrorsInferenceEngine(KnowledgeEngine)
# define listbox
list1 = Listbox(window, height=6, width=90)
list1.grid(row=4, column=0, rowspan=6, columnspan=2)
# Attach scrollbar to the list
sb1 = Scrollbar(window)
sb1.grid(row=4, column=2, rowspan=6)
list1.configure(yscrollcommand=sb1.set)
sb1.configure(command=list1.yview)
list1.insert(tk.END, display_results())
# Define buttons
b1 = Button(window, text="View Results", width=12, bg="red",command=lambda: Ledger_errors.display_results())
b1.grid(row=3, column=3)
window.mainloop()
请尝试将此代码缩减为一个。似乎有很多代码是不需要的,以便重现您遇到的问题。请尝试将此代码减少到一个较低的级别。为了重现您遇到的问题,似乎有很多代码是不需要的。