2016-03-24 4 views
-1

ラズベリーパイに指紋スキャナを使用し、tkinterを使用して複数のページを作成しました。私は、指紋検索の後、ウェルカムページから次のページに移動したいと考えています。データベースに一致するものがあれば、次のページに移動することができます。それ以外の場合は、ウェルカムページに残ります。ここで指紋照合がデータベースに見つかった後、tkinterで新しいページを開く方法

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

指紋その後、search.py

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

を使用しています。私たちが答えることができる明確な質問があるように[mcve]を投稿してください。 –

+0

こんにちはPM 2Ring、それは私がページを作成した方法です –

答えて

0
root2 = Toplevel(self.master) 
#when iv done this iv made a notepad file with the root levels and page 
#associated with them this makes it easier when opening and closing pages 

mygui2 = nameofclass(root2) 
#note that the root2 which i just made above is used here 
#when i was doing mine i used mygui and root for all of them but changed 
#number when opeing different webpages 

そして、ページを閉じることですそれはあなたがあなたの "ページ" を定義した方法によって異なり

self.master.destroy() 
関連する問題