Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 class returns NoneType Object
#1
Hello, I am trying to read PDF file in Gui class and then I will use that read file to do some graphical process.

Here is the Gui class:
Gui.py:

# Multi-frame tkinter application v2.3
import os
import sys
sys.path.insert(0, "..")
import tkinter as tk
import tkinter.filedialog


class SampleApp(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self._frame = None
        self.switch_frame(StartPage)
        self.title("Welcome to EMC Deep Learning Application")
        self.geometry('1000x500')
        self.pdf_File = None

    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.grid()

##    def on_change(e):
##        print e.widget.get()



class StartPage(tk.Frame):
    def __init__(self, master):
        tk.Frame.__init__(self, master)
        tk.Label(self, text="Ne işlem yapılacak?").grid(row=1,column=1)
        tk.Button(self, text="Öğret",
                          command=lambda: master.switch_frame(PageOne)).grid()
        tk.Button(self, text="Öğren",
                          command=lambda: master.switch_frame(PageTwo)).grid()

class PageOne(tk.Frame):
    def __init__(self, master):
        tk.Frame.__init__(self, master)
        tk.Label(self, text="Öğretmek için orjinal test sonuçlarının yüklü olduundan emin olun").grid(row=1,column=1)
        tk.Button(self, text="Ana Sayfaya Dön",
                  command=lambda: master.switch_frame(StartPage)).grid(row=2,column=1)
        
        vendorVar = tk.StringVar(self) #create a panel vendor variable
        vendors = {'BOE','SAMSUNG','LG'}
        vendorVar.set('BOE') # set default opt
        self.vendorVar = vendorVar
        vendorLabel = tk.Label(self, text="Marka:")
        vendorLabel.grid(row = 3, column = 1)
        popMenuVendor = tk.OptionMenu(self, vendorVar, *vendors)
        popMenuVendor.grid(row=4,column=1)

        techVar = tk.StringVar(self) #create a panel vendor variable
        techs = {'LCD','OLED','QDOT'}
        techVar.set('LCD') # set default opt
        self.techVar = techVar
        techLabel = tk.Label(self, text="Teknoloji:")
        techLabel.grid(row = 3, column = 2)
        popMenuTech = tk.OptionMenu(self, techVar, *techs)
        popMenuTech.grid(row=4,column=2)

        sizeBox = tk.IntVar(self)
        tk.Label(self, text="Ekran Boyutu:").grid(row = 3, column = 3)
        sizeBox = tk.Entry(self)
        sizeBox.grid(row=4,column=3)
        self.sizeBox = sizeBox

        tk.Label(self, text="PDF dosyası").grid(row = 3, column = 4)
        pdfButton = tk.Button(self, text="Yükle",
                  command=lambda: self.pdfUpload())
        pdfButton.grid(row=4,column=4)
        
        buttonT = tk.Button(self, text="Goster", command=self.ok)
        buttonT.grid(row=5,column=1)
    def ok(self):
        print ("vendor is: " + self.vendorVar.get() )
        print("tech is " +  self.techVar.get() )
        if(self.sizeBox.get().isdigit()):
            print("size is: " + self.sizeBox.get())
        else:
            print("not an integer!")
        master.pdf_File = self.pdf_File

    def pdfUpload(self):
        self.pdf_File = tk.filedialog.askopenfilename(initialdir = "/Users/26015017/Desktop/",title = "Dosya Seçin",filetypes = [("pdf files","*.pdf")])
##        os.startfile(self.pdf_File)
##        master.quit()
        
class PageTwo(tk.Frame):
    def __init__(self, master):
        tk.Frame.__init__(self, master)
        tk.Label(self, text="This is page two").pack(side="top", fill="x", pady=10)
        tk.Button(self, text="Return to start page",
                  command=lambda: master.switch_frame(StartPage)).pack()

if __name__ == "__main__":
    app = SampleApp()
    
    app.mainloop()
and here is the main file:
TestBench.py:

import cv2
import tkinter
import numpy as np
import matplotlib.pylab as plt
import matplotlib.pyplot as plot 
'exec(%matplotlib inline)'
import tabula
from classes.Graphs import *
from classes.Gui import *

from pdf2image import convert_from_path
from pdf2image import convert_from_bytes
##tkinter._test()

app = SampleApp()
    
app.mainloop()

pdf_File = app.pdf_File
os.startfile(pdf_File)
##pdf2PNG = convert_from_path('images/ex2.Pdf', 500)
pdf_File.save('images/temp/ex2.pdf', 'PDF')
##pdf2PNG = convert_from_bytes(app.pdf_File, 500)

tabula.convert_into("images/ex2.pdf", "images/ex2.csv", output_format="csv", pages='all')
tabula.convert_into(pdf2PNG, "images/ex2.csv", output_format="csv", pages='all')

pdf2PNG[0].save('images/temp/ex2.png', 'PNG')

img = cv2.imread('images/temp/ex2.png')




graph1 = BasicGraph(1, img)

print("Graph revision: ", graph1.revision)
print("Y origin is: ", graph1.yOrigin)
print("xAxis legth is: ", graph1.xAxisLength)
print("X origin is: ", graph1.xOrigin)
print("yAxis legth is: ", graph1.yAxisLength)
print("47 Limit Len: ", graph1.limit47Length)
print("47 Limit Y is: ", graph1.y47)
print("40 Limit Len is: ", graph1.limit40Length)
print("40 Limit Y is: ", graph1.y40)
print("Last data on X axis is: ", graph1.lastDataX)
print("Last y axis is: ", graph1.lastXAxis)
print("unitY is : ", graph1.unitY)


plot.plot(graph1.hrzData)
plot.plot(graph1.vrtData)
plot.axis([0, 970, 0, 80])
plot.show()

cv2.waitKey(0)
cv2.destroyAllWindows()
what I get (after selecting the file) is like this:
Quote:Traceback (most recent call last):
File "D:\Users\26015017\Desktop\Deneme9\testBench_2.py", line 20, in <module>
os.startfile(pdf_File)
TypeError: startfile: filepath should be string, bytes or os.PathLike, not NoneType

I am not rally familiar with OOP so am currently learning but as I understand, the program calls the class as expected,
app = SampleApp()
reads the file correctly and opens the file after reading correctly in class script:
    def pdfUpload(self):
        self.pdf_File = tk.filedialog.askopenfilename(initialdir = "/Users/26015017/Desktop/",title = "Dosya Seçin",filetypes = [("pdf files","*.pdf")])
        os.startfile(self.pdf_File)
When I run os.startfile I see the document I choosed (because it happens under gui.py). And till I close the window, I don't get the warning so I think after I close the window, all the variables in the class vanishes too. So my question is 'what is happening here?' If I correctly assessed the problem, how can I overcome this problem?
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  AttributeError: 'NoneType' object has no attribute 'label' : What's wrong ? Etienne17 1 340 Dec-13-2019, 06:57 PM
Last Post: ibreeden
  TypeError: 'NoneType' object is not subscriptable Jmekubo 5 16,080 Nov-07-2019, 03:59 AM
Last Post: markfilan
  Object and type class Uchikago 2 260 Jul-28-2019, 10:35 AM
Last Post: DeaD_EyE
  Return a value when I equal an object from a class ihouses 4 382 Jul-10-2019, 02:44 AM
Last Post: SheeppOSU
  How to save a class object to a file? SheeppOSU 2 359 Jun-22-2019, 11:54 PM
Last Post: metulburr
  AttributeError: 'NoneType' object has no attribute 'get' ahmeddedo 1 3,069 May-27-2019, 05:57 AM
Last Post: heiner55
  Function returns "NoneType" eoins 3 662 May-22-2019, 10:43 PM
Last Post: micseydel
  saving (in text or binary) an object under a defined class cai0824 3 500 May-12-2019, 08:55 AM
Last Post: snippsat
  TypeError: object of type 'NoneType' has no len() - what do it mean? leviathan54 4 2,680 Apr-20-2019, 12:04 PM
Last Post: leviathan54
  How do I use this? TypeError: 'NoneType' object does not support item assignment ejected 9 7,631 Mar-26-2019, 05:06 AM
Last Post: ejected

Forum Jump:


Users browsing this thread: 1 Guest(s)