Byamukama Oscar Ответов: 1

Как открыть новую страницу с помощью tkinter в Python с помощью сканера отпечатков пальцев


я создал несколько интерфейсов в Tkinter с помощью python, и я хотел бы отобразить страницу ("вы зарегистрированы"), если совпадение найдено в базе данных else ("вы не зарегистрированы").
код для нескольких страниц

import Tkinter as tk
from Tkinter import IntVar
# python3
#import Tkinter as tk   # python

TITLE_FONT = ("Helvetica", 18, "bold")

class oscarApp(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        # the container is where we'll stack a bunch of frames
        # on top of each other, then the one we want visible
        # will be raised above the others
        container = tk.Frame(self,bg="green")
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}
        for F in (StartPage, PageOne, PageTwo,PageFour):
            page_name = F.__name__
            frame = F(container, self)
            self.frames[page_name] = frame

            # put all of the pages in the same location;
            # the one on the top of the stacking order
            # will be the one that is visible.
            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame("StartPage")

    def show_frame(self, page_name):
        '''Show a frame for the given page name'''
        frame = self.frames[page_name]
        frame.tkraise()




class StartPage(tk.Frame):


    def __init__(self, parent, controller):

        tk.Frame.__init__(self, parent)
        self.controller = controller
        label = tk.Label(self,bg="green",
                         text="PLease place your thumb print\n on fingerprint scanner to start ",
                         font=TITLE_FONT)
        label.pack(side="top", fill="x", pady=10)
        button1 = tk.Button(self, text="NEXT",bg="yellow",
                                    command=lambda: controller.show_frame("PageOne"))

        button1.pack(pady=10)

class PageOne(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        label = tk.Label(self, text="This is page ONE", font=TITLE_FONT)
        label.pack(side="top", fill="x", pady=10)
        label = tk.Label(self, text="YOU ARE NOT REGISTERED", font=TITLE_FONT)
        label.pack(side="top", fill="x", pady=10)
        button = tk.Button(self, text="NEXT",
                           command=lambda: controller.show_frame("StartPage"))
        button.pack()


class PageTwo(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        label = tk.Label(self, text="you are registered\n press NEXT to START", font=TITLE_FONT,bg="green")
        label.pack(side="top", fill="x", pady=10)
        button = tk.Button(self, text="NEXT",
                           command=lambda: controller.show_frame("pagefour"))
        button.pack()


class PageFour(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        label = tk.Label(self, text="This is page four", font=TITLE_FONT)
        label.pack(side="top", fill="x", pady=10)
        label = tk.Label(self, text="THANKS ", font=TITLE_FONT)
        label.pack(side="top", fill="x", pady=10)
        button = tk.Button(self, text="Go to the start page",
                           command=lambda: controller.show_frame("StartPage"))
        button.pack()


if __name__ == "__main__":

        app = oscarApp()
        app.mainloop()


code finger print is 


import hashlib
from pyfingerprint.pyfingerprint import PyFingerprint


## Search for a finger
##

## Tries to initialize the sensor
try:
    f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000)

    if ( f.verifyPassword() == False ):
        raise ValueError('The given fingerprint sensor password is wrong!')

except Exception as e:
    print('The fingerprint sensor could not be initialized!')
    print('Exception message: ' + str(e))
    exit(1)

## Gets some sensor information
print('Currently stored templates: ' + str(f.getTemplateCount()))

## Tries to search the finger and calculate hash
try:
    print('Waiting for finger...')

    ## Wait that finger is read
    while ( f.readImage() == False ):
        pass

    ## Converts read image to characteristics and stores it in charbuffer 1
    f.convertImage(0x01)

    ## Searchs template
    result = f.searchTemplate()

    positionNumber = result[0]
    accuracyScore = result[1]

    if ( positionNumber == -1 ):
        print('No match found!')
        exit(0)
    else:
        print('Found template at position #' + str(positionNumber))
        print('The accuracy score is: ' + str(accuracyScore))

    ## OPTIONAL stuff
    ##

    ## Loads the found template to charbuffer 1
    f.loadTemplate(positionNumber, 0x01)

    ## Downloads the characteristics of template loaded in charbuffer 1
    characterics = str(f.downloadCharacteristics(0x01))

    ## Hashes characteristics of template
    print('SHA-2 hash of template: ' + hashlib.sha256(characterics).hexdigest())

except Exception as e:
    print('Operation failed!')
    print('Exception message: ' + str(e))
    exit(1)


Что я уже пробовал:

я попытался создать поиск кода шаблона отпечатка пальца, и он хорошо работает и создает несколько страниц.я хотел бы объединить их вместе

1 Ответов

Рейтинг:
1

Cygnus2k

- Привет! Я использовал его с последовательным преобразователем в USB (CP2102)
Скрипт python определит порт /dev/ttyUSBx как действительный.