我使用tkinter创建GUI,
我做了茎处理按钮。
我现在想做的是,我希望将词干提取过程中的值显示给另一个类。
如何将过程按钮中的值显示到另一个类中。
这是我的代码
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog
from tkinter import messagebox
from PyPDF2 import PdfFileReader
import string
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
from nltk.stem import PorterStemmer
import sqlite3
class Classify(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self._frame = None
self.switch_frame(HomePage)
self.geometry("800x500")
self.title("Klasifikasi Dokumen")
def switch_frame(self, frame_class):
"""Destroys current frame and replaces it with a new one."""
new_frame = frame_class(self)
if self._frame is not None:
self._frame.destroy()
self._frame = new_frame
self._frame.pack()
class HomePage(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
start_label = tk.Label(self, text="Klasifikasi Dokumen Berdasarkan Algoritma SVM", font = "Times 25", relief = "solid")
btnDataSampel = tk.Button(self, text="Data Sampel", font = "Times 20",
command=lambda: master.switch_frame(DataSampel), height = 1, width = 30)
btnDataUji = tk.Button(self, text="Data Uji", font = "Times 20",
command=lambda: master.switch_frame(DataUji), height = 1, width = 30)
btnExit = tk.Button(self, text="Exit", font = "Times 20",
command=self.Exit, height=1, width=30)
start_label.grid(row = 0, column = 1, padx=10, pady=50)
btnDataSampel.grid(row = 2, column = 1, padx=10, pady=20)
btnDataUji.grid(row = 4, column = 1, padx=10, pady=20)
btnExit.grid(row = 6, column = 1, padx=10, pady=20)
def Exit(self):
msg = messagebox.askyesno("Klasifikasi Dokumen", "Apa Anda Yakin Ingin Keluar?")
if(msg):
exit()
class DataUji(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
labelframe = tk.LabelFrame(self, text="Data Uji")
labelframe.grid(row = 0, column = 0, padx = 5, pady = 5)
#membuat label
lb_jdl = tk.Label(labelframe, text="Judul")
lb_jdl.grid(row=2, column=0, pady = 5)
lb_pen = tk.Label(labelframe, text="Penulis")
lb_pen.grid(row=3, column=0, pady = 5)
lb_keyword = tk.Label(labelframe, text="Keyword")
lb_keyword.grid(row=4, column=0, pady = 5)
lb_abs = tk.Label(labelframe, text="Abstrak")
lb_abs.grid(row=5, column=0, pady = 5)
#membuat entry
self.pathlabel = tk.StringVar()
path = tk.Entry(labelframe, textvariable = self.pathlabel, width=100)
path.grid(row=1, column=1, pady = 5)
self.judul = tk.StringVar()
entJudul = tk.Entry(labelframe, textvariable = self.judul, width=100)
entJudul.grid(row=2, column=1, pady = 5)
self.penulis = tk.StringVar()
entPnls = tk.Entry(labelframe, textvariable = self.penulis, width=100)
entPnls.grid(row=3, column=1, pady = 5)
self.keyword = tk.StringVar()
entKey = tk.Entry(labelframe, textvariable = self.keyword, width=100)
entKey.grid(row=4, column=1, pady = 5)
self.txtAbs = tk.Text(labelframe, height=5, wrap = tk.WORD)
self.txtAbs.grid(row=5, column=1, pady = 5)
#membuat Button
btnbrw = tk.Button(labelframe, text="Choose File", width=10, command = self.BrowseFunc)
btnbrw.grid(row=1, column=2, padx = 2)
btnProses = tk.Button(labelframe, text="Proses", width=10, command=self.Proses)
btnProses.grid(row=6, column=1, padx=2, pady = 5)
def BrowseFunc(self):
filename = filedialog.askopenfilename()
print(filename)
self.pathlabel.set(filename)
self.get_info(filename)
def get_info(self, path):
with open(path, 'rb') as f:
pdf = PdfFileReader(f)
info = pdf.getDocumentInfo()
page = pdf.getPage(0)
text = page.extractText()
self.judul.set(info.title)
self.penulis.set(info.author)
self.keyword.set(info.subject)
self.txtAbs.insert(tk.END, text)
def Proses(self):
absText = self.txtAbs.get(0.0, tk.END)
print("\n ABSTRAK \n", absText)
#membuang tanda baca
self.punc = str.maketrans("~!@#$%^&*()_+-={}:;<>?,.", 24*" ")
self.rem_punc = absText.translate(self.punc)
print("\n PUNCTUATION \n", self.rem_punc)
#membuat tokenisasi
self.enthsltkn = word_tokenize(self.rem_punc.lower())
print("\n TOKENIZATION \n", self.enthsltkn)
#membuat stopword
self.stopword = set(stopwords.words('english'))
self.fill_word = [item for item in self.enthsltkn if item not in self.stopword]
print("\n STOPWORD \n", self.fill_word)
#membuat stemming
self.stemmer = PorterStemmer()
self.stemming = ' '.join(self.stemmer.stem(w) for w in self.fill_word).split()
print("\n HASIL STEM \n", self.stemming)
class Hitung(DataUji):
def __init__(self, master):
tk.Frame.__init__(self, master)
labelframe = tk.LabelFrame(self, text="Pre-processing")
labelframe.grid(row = 0, column = 0, padx = 5, pady = 5)
# membuat label
lb_jdl = tk.Label(labelframe, text="Judul")
lb_jdl.grid(row=0, column=0, pady=5)
lb_pen = tk.Label(labelframe, text="Penulis")
lb_pen.grid(row=2, column=0, pady=5)
lb_keyword = tk.Label(labelframe, text="Keyword")
lb_keyword.grid(row=4, column=0, pady=5)
#Text
textTokenization = tk.Text(labelframe, height=5)
textTokenization.grid(row=1, column=0, pady = 5)
textStopword = tk.Text(labelframe, height=5)
textStopword.grid(row=3, column=0, pady=5)
textStemming = tk.Text(labelframe, height=5)
textStemming.grid(row=5, column=0, pady=5)
if __name__ == "__main__":
app = Classify()
app.mainloop()
当我单击处理按钮时,我具有文本框中的值
当我单击过程按钮并将其显示在另一个类中时,如何将值发送给另一个类。