Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.38 KB | None | 0 0
  1. #
  2. #  Like 'names7.py' but now with the filter for month number via comboBox
  3. #
  4. import sqlite3
  5. import sys
  6.  
  7. import tkinter
  8. from tkinter import ttk
  9. from tkinter.scrolledtext import *
  10. from tkinter.constants import END
  11.  
  12. myTitle = 'DataBase processing (%s)' % str.split( sys.argv[ 0 ], '\\' )[ -1 ]
  13. months = [ ]
  14. for month in range( 12 ) :
  15.     months.append( "%02d" % ( month + 1, ) )
  16.      
  17. class Application:
  18.     def __init__( self, root ):
  19.         self.root = root
  20.         self.root.title( myTitle )
  21.         ttk.Frame( self.root, width = 600, height = 500 ).pack( )
  22.        
  23.         self.myLabel = ttk.Label( self.root, text = 'Month:' ).place( x = 20, y = 13 )
  24.         self.myComboBox = ttk.Combobox( self.root, values = months, width = '3' )
  25.         self.myComboBox.place( x = 65, y = 13 )
  26.         self.myComboBox.set( months[ 0 ] )
  27.         ttk.Button( self.root, command = self.ProcessData, text = 'Process data from database', width = '30' ).place( x = 130, y = 10 )
  28.         self.myScrolledText = tkinter.scrolledtext.ScrolledText( self.root, width = 70, bg = 'yellow', height = 27 )
  29.         self.myScrolledText.place( x = 10, y = 50 )
  30.         ttk.Button( self.root, command = self.Exit, text = 'Exit', width = '30' ).place( x = 390, y = 10 )
  31.  
  32.     def Exit( self ):
  33.         sys.exit( )
  34.  
  35.     def ProcessData( self ):
  36.         connection = sqlite3.connect( 'myFourthDataBase.sqlite' )
  37.         cursor = connection.cursor()
  38.  
  39.         cursor.execute( "SELECT children.name, families.surname, children.date, states.state FROM families, children, states WHERE families.id = children.familyID AND states.id = families.stateID ORDER BY states.id, children.date" )
  40.         data = cursor.fetchall()
  41.  
  42.         No = 0
  43.         myText = ''
  44.         for myData in data :
  45.             if str.split( myData[ 2 ], '-' )[ 1 ] == self.myComboBox.get() :
  46.                 No += 1
  47.                 myText += "%4d: %-14s  %-14s %-12s %-20s\n" % ( No, myData[ 0 ], myData[ 1 ], myData[ 2 ], str.strip( myData[ 3 ] ) )
  48.  
  49.         self.myScrolledText.destroy( )
  50.         self.myScrolledText = tkinter.scrolledtext.ScrolledText( self.root, width = 70, bg = 'yellow', height = 27 )
  51.         self.myScrolledText.place( x = 10, y = 50 )
  52.         self.myScrolledText.insert( END, myText )
  53.  
  54.         connection.close()
  55.  
  56.  
  57. if __name__ == '__main__':
  58.     root = tkinter.Tk( )
  59.     Application( root )
  60.     root.mainloop( )
  61.  
  62. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement