Handbook of Computer Programming with Python by Xanthidis Dimitrios;Manolas Christos;Xanthidou Ourania K.;Wang Han-I;
Author:Xanthidis, Dimitrios;Manolas, Christos;Xanthidou, Ourania K.;Wang, Han-I;
Language: eng
Format: epub
Publisher: CRC Press LLC
Published: 2022-10-17T00:00:00+00:00
7.4.3 The SELECT Statement Using GUI
Arguably, if one aims to develop a user-oriented application, it is necessary to wrap the application with a user-friendly GUI. An extensive introduction to the most important GUI widgets (e.g., labels, entry boxes, radio buttons, buttons) and their application is provided in earlier chapters of this book. In the current context, it is assumed that the focus is on the creation of a grid-based layout that will be used to host the results of the SQL queries. In such a case, a grid layout manager could be used. The following Python script showcases the development and execution of a condition-based MySQL SELECT query using a fully deployed GUI:
1 import mysql.connector 2 import tkinter as tk 3 from tkinter import ttk 4 5 global tableName, attributeName, radioButton, textVar 6 global minLabel, maxLabel, textualLabel; global textualEntry 7 global selectionsFrame, resultsFrame; global columnName, columnType 8 global minCondScale, maxCondScale; global tablesCombo, columnsCombo 9 global connect, cursor, config; global tables, columns 10 global minCond, maxCond; global minValue, maxValue, numCols 11 12 # Create the frame to select the table for the query and its attributes 13 def selectionGUI(): 14 global tables, columns; global tablesCombo, columnsCombo 15 global tableName, radioButton, textVar 16 global selectionsFrame, resultsFrame 17 global minLabel, maxLabel, textualLabel 18 global minCondScale, maxCondScale; global textualEntry 19 20 # The frame for the query selections of the user 21 selectionsFrame=tk.LabelFrame(winFrame, text='Query selections') 22 selectionsFrame.config(bg = 'light grey', fg = 'red', bd = 2, 23 relief = 'sunken') 24 selectionsFrame.grid(column = 0, row = 0) 25 26 # Create the combobox to hold the tables available in the db 27 tablesLabel = tk.Label(selectionsFrame, 28 text = "Tables available:", bg = "light grey") 29 tablesLabel.grid(column = 0, row = 0) 30 tablesCombo = ttk.Combobox(selectionsFrame, 31 textvariable = tableName, width = 15) 32 tablesCombo['values'] = tables; tablesCombo.current(0) 33 tablesCombo.grid(column = 1, row = 0) 34 35 # Button updates the attributes combo based on the table selection 36 updateAttributesButton = tk.Button(selectionsFrame, 37 text = 'Update Attributes', relief = 'raised', width = 15) 38 updateAttributesButton.bind('<Button-1>', 39 lambda event: updateAttributes()) 40 updateAttributesButton.grid(column = 2, row = 0) 41 42 # Create the button to run the query 43 runButton = tk.Button(selectionsFrame, text = 'Run Query', 44 relief = 'raised', width = 15) 45 runButton.bind('<Button-1>', lambda event: runQuery()) 46 runButton.grid(column = 3, row = 0) 47 48 # Update the columns combo based on the table selection 49 columnsLabel = tk.Label(selectionsFrame, 50 text = "Select attribute:", bg = "light grey") 51 columnsLabel.grid(column = 0, row = 1) 52 columnsCombo = ttk.Combobox(selectionsFrame, 53 textvariable = attributeName, width = 15) 54 columnsCombo.grid(column = 1, row = 1) 55 56 # Check whether selected attribute is numeric or text 57 numericalAttribute = tk.Radiobutton (selectionsFrame, 58 text = 'Numerical
attribute', width = 10, height = 2, 59 bg = 'light green', variable = radioButton, value = 1, 60 command = radioClicked).grid(column = 2, row = 1) 61 textAttribute = tk.Radiobutton (selectionsFrame, 62 text = 'Text
attribute', width = 10, height = 2, 63 bg = 'light green', variable = radioButton, value = 2, 64 command = radioClicked).
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Exploring Deepfakes by Bryan Lyon and Matt Tora(7475)
Robo-Advisor with Python by Aki Ranin(7355)
Offensive Shellcode from Scratch by Rishalin Pillay(5969)
Ego Is the Enemy by Ryan Holiday(4900)
Microsoft 365 and SharePoint Online Cookbook by Gaurav Mahajan Sudeep Ghatak Nate Chamberlain Scott Brewster(4745)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4421)
Python for ArcGIS Pro by Silas Toms Bill Parker(4046)
Elevating React Web Development with Gatsby by Samuel Larsen-Disney(3751)
Machine Learning at Scale with H2O by Gregory Keys | David Whiting(3465)
Learning C# by Developing Games with Unity 2021 by Harrison Ferrone(3265)
Speed Up Your Python with Rust by Maxwell Flitton(3221)
Liar's Poker by Michael Lewis(3197)
OPNsense Beginner to Professional by Julio Cesar Bueno de Camargo(3182)
Extreme DAX by Michiel Rozema & Henk Vlootman(3158)
Agile Security Operations by Hinne Hettema(3110)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic and Jasmin Redzepagic(3100)
Essential Cryptography for JavaScript Developers by Alessandro Segala(3073)
Cryptography Algorithms by Massimo Bertaccini(2989)
AI-Powered Commerce by Andy Pandharikar & Frederik Bussler(2970)
