#Import Needed Libraries import sys from PyQt4.QtCore import * from PyQt4.QtGui import * # Define Form as a Class class Form( QDialog): # Form Constructor def __init__(self, parent=None): super(Form, self).__init__(parent) # Set Window Title self.setWindowTitle("Soup Sales") # Create a Layout for Widgets layout = QVBoxLayout() # 1.1 Add lineedit1 to layout layout.addWidget(self.lineedit1) # 1.2 Create Push Button 1: "Load Data" self.pbutton1 = QPushButton("Load Data") # 1.3 Add pbutton1 to layout layout.addWidget(self.pbutton1) # 1.4 Add Field 1: "Enter Input File Name" self.lineedit1.setPlaceholderText("Enter Input File Name") # 2.1 Add lineedit2 to layout for Button "Total Row Count" layout.addWidget(self.lineedit2) # 2.2 Create Push Button 2: "Total Row Count" self.pbutton2 = QPushButton("Total Row Count") # 2.3 Add pbutton2 to layout layout.addWidget(self.pbutton2) # 2.4 Add Field 2: "Enter Total Row Count" self.lineedit1.setPlaceholderText("Enter Total Row Count") # 3.1 Add lineedit3 to layout for List Table layout.addWidget(self.lineedit3) # 3.2 Create Push Button 3: "List Table" self.pbutton3 = QPushButton("List Table") # 3.3 Add pbutton3 to layout layout.addWidget(self.pbutton3) # 3.4 Add Field 3: "Enter Table Name" self.lineedit3.setPlaceholderText("Enter Table Name") # 4.1 Add lineedit4 to layout for "Custom SQL Test" layout.addWidget(self.lineedit4) # 4.2 Create Push Button 4: "Custom SQL Test" self.pbutton4 = QPushButton("Custom SQL Test") # 4.3 Add pbutton4 to layout "Custom SQL Test" layout.addWidget(self.pbutton4) # 4.4 Add Field 4: "Enter SQL Statement" self.lineedit3.setPlaceholderText("Enter SQL Statement") # 5.1 Add lineedit5 to layout for Quit layout.addWidget(self.lineedit5) # 5.2 Create Push Button 5: "Quit" self.pbutton5 = QPushButton("Quit") # 5.3 Add pbutton5 to layout layout.addWidget(self.pbutton5) # Apply the Layout to the Form self.setLayout(layout) # 1.5 Actives pbutton1 self.lineedit1.setFocus() # 1.6 Connects pbutton1 to a method self.connect(self.pbutton1, SIGNAL("clicked()"),self.button1Pressed) # 2.5 Actives pbutton2 self.lineedit2.setFocus() # 2.6 Connects pbutton2 to a method self.connect(self.pbutton2, SIGNAL("clicked()"),self.button2Pressed) # 3.5 Actives pbutton3 self.lineedit3.setFocus() # 3.6 Connects pbutton3 to a method self.connect(self.pbutton3, SIGNAL("clicked()"),self.button3Pressed) # 4.5 Actives pbutton4 self.lineedit4.setFocus() # 4.6 Connects pbutton4 to a method self.connect(self.pbutton4, SIGNAL("clicked()"),self.button4Pressed) # 5.5 Actives pbutton5 self.lineedit5.setFocus() # 5.6 Connects pbutton5 to a method self.connect(self.pbutton5, SIGNAL("clicked()"),self.button5Pressed) # 6.5 Actives pbutton6 self.lineedit6.setFocus() # 6.6 Connects pbutton6 to a method self.connect(self.pbutton6, SIGNAL("clicked()"),self.button6Pressed) # Form Method Button 1 - Method to be involved when pbutton1 is pressed def button1Pressed(self): #Parsing the Input File import sqlite3 conn = sqlite3.connect("MyDB.db") cur = conn.cursor() c.execute('CREATE TABLE {tn} ({nf} {ft})'\ .format(tn=table_name1, nf=new_field, ft=field_type)) f = open("SoupSalesTextData.txt", "r") linecount = 0 line = f.readline() while line != "" and linecount < 5: linecount = linecount + 1 line = line.replace("\n","") linelist = line.split("\t") # Form Method Button 2 -Method to be involved when pbutton2 is pressed def button2Pressed(self): # Form Method Button 3 - Method to be involved when pbutton3 is pressed def button3Pressed(self): # Form Method Button 4 - Method to be involved when pbutton4 is pressed def button4Pressed(self): # Form Method Button 5 - Method to be involved when pbutton5 is pressed def button5Pressed(self): self.done(1) app.quit() # End of Form Class Definition # Inserting a Sales Row def InsertSales(record): TrxId = int(record[0]) DoY = int(record[1]) StoreId = int(record[5]) SoupId = int(record[13]) PromoId = int(record[18]) Sales = float(record[22]) row = [TrxId,DoY,StoreId,SoupId, PromoId, Sales] # cur.execute("Insert into Sales values", row) print "Row Inserted: ", row # Form Method Button 5 - Method to be involved when button is pressed def button5Pressed(self): self.done(1) app.quit() # Define Form as a Class class Form( QDialog): # Form Constructor def __init__(self, parent=None): super(Form, self).__init__(parent) self.lineedit0 = QLineEdit("File Name") self.label1 = QLabel("Select a Function") self.pbutton1 = QPushButton("Character Count") self.lineedit1 = QLineEdit("") self.pbutton2 = QPushButton("Line Count") self.lineedit2 = QLineEdit("") self.pbutton3 = QPushButton("Word Count") self.lineedit3 = QLineEdit("") self.pbutton4 = QPushButton("Count Occurences") self.lineedit4 = QLineEdit("Enter Word to be Counted") self.pbutton5 = QPushButton("Count All Occurences") self.lineedit5 = QLineEdit("Results Shown in IDLE") self.pbuttonQuit = QPushButton("Quit") layout = QVBoxLayout() layout.addWidget(self.lineedit0) layout.addWidget(self.label1) layout.addWidget(self.pbutton1) layout.addWidget(self.lineedit1) layout.addWidget(self.pbutton2) layout.addWidget(self.lineedit2) layout.addWidget(self.pbutton3) layout.addWidget(self.lineedit3) layout.addWidget(self.pbutton4) layout.addWidget(self.lineedit4) layout.addWidget(self.pbutton5) layout.addWidget(self.lineedit5) layout.addWidget(self.pbuttonQuit) self.setLayout(layout) self.lineedit1.setFocus() self.connect(self.pbutton1, SIGNAL("clicked()"),self.button1Pressed) self.connect(self.pbutton2, SIGNAL("clicked()"),self.button2Pressed) self.connect(self.pbutton3, SIGNAL("clicked()"),self.button3Pressed) self.connect(self.pbutton4, SIGNAL("clicked()"),self.button4Pressed) self.connect(self.pbutton5, SIGNAL("clicked()"),self.button5Pressed) self.connect(self.pbuttonQuit, SIGNAL("clicked()"),self.buttonQuitPressed) self.setWindowTitle("File Processor") # End of Form Class Definition # Create Application app = QApplication(sys.argv) # Create Instance of Form form = Form() # Show the Form form.show() # Start Event Handler Loop app.exec_()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question