Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Like 'names7.py' but now with the filter for month number via comboBox
- #
- import sqlite3
- import sys
- import tkinter
- from tkinter import ttk
- from tkinter.scrolledtext import *
- from tkinter.constants import END
- myTitle = 'DataBase processing (%s)' % str.split( sys.argv[ 0 ], '\\' )[ -1 ]
- months = [ ]
- for month in range( 12 ) :
- months.append( "%02d" % ( month + 1, ) )
- class Application:
- def __init__( self, root ):
- self.root = root
- self.root.title( myTitle )
- ttk.Frame( self.root, width = 600, height = 500 ).pack( )
- self.myLabel = ttk.Label( self.root, text = 'Month:' ).place( x = 20, y = 13 )
- self.myComboBox = ttk.Combobox( self.root, values = months, width = '3' )
- self.myComboBox.place( x = 65, y = 13 )
- self.myComboBox.set( months[ 0 ] )
- ttk.Button( self.root, command = self.ProcessData, text = 'Process data from database', width = '30' ).place( x = 130, y = 10 )
- self.myScrolledText = tkinter.scrolledtext.ScrolledText( self.root, width = 70, bg = 'yellow', height = 27 )
- self.myScrolledText.place( x = 10, y = 50 )
- ttk.Button( self.root, command = self.Exit, text = 'Exit', width = '30' ).place( x = 390, y = 10 )
- def Exit( self ):
- sys.exit( )
- def ProcessData( self ):
- connection = sqlite3.connect( 'myFourthDataBase.sqlite' )
- cursor = connection.cursor()
- 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" )
- data = cursor.fetchall()
- No = 0
- myText = ''
- for myData in data :
- if str.split( myData[ 2 ], '-' )[ 1 ] == self.myComboBox.get() :
- No += 1
- myText += "%4d: %-14s %-14s %-12s %-20s\n" % ( No, myData[ 0 ], myData[ 1 ], myData[ 2 ], str.strip( myData[ 3 ] ) )
- self.myScrolledText.destroy( )
- self.myScrolledText = tkinter.scrolledtext.ScrolledText( self.root, width = 70, bg = 'yellow', height = 27 )
- self.myScrolledText.place( x = 10, y = 50 )
- self.myScrolledText.insert( END, myText )
- connection.close()
- if __name__ == '__main__':
- root = tkinter.Tk( )
- Application( root )
- root.mainloop( )
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement