Advertisement
Guest User

sniper.py

a guest
Oct 7th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.07 KB | None | 0 0
  1. from PyQt5 import QtGui
  2. from PyQt5.QtWidgets import QApplication, QDialog, QLineEdit, QPushButton, QMessageBox, QVBoxLayout
  3. import sys
  4. #import MySQLdb as mdb
  5. import mysql.connector
  6. import pymysql as mdb
  7.  
  8.  
  9. mdb = mysql.connector.connect(
  10.   host="db4free.net",
  11.   user="dodo45yo",
  12.   password="U8y$YrHc4s!9T!7",
  13.   database="yoyopo"
  14.   )
  15.  
  16. class Window(QDialog):
  17.     def __init__(self):
  18.         super().__init__()
  19.  
  20.         self.title = "PyQt5 Insert Data"
  21.         self.top = 100
  22.         self.left = 100
  23.         self.width = 300
  24.         self.height = 100
  25.  
  26.  
  27.         self.InitWindow()
  28.  
  29.  
  30.     def InitWindow(self):
  31.  
  32.         self.setWindowIcon(QtGui.QIcon("icon.png"))
  33.         self.setWindowTitle(self.title)
  34.         self.setGeometry(self.top, self.left, self.width, self.height)
  35.  
  36.         vbox = QVBoxLayout()
  37.  
  38.         self.name = QLineEdit(self)
  39.         self.name.setPlaceholderText('Please Enter Your Name')
  40.         self.name.setStyleSheet('background:yellow')
  41.         self.name.setFont(QtGui.QFont("Sanserif", 15))
  42.  
  43.         vbox.addWidget(self.name)
  44.  
  45.         self.email = QLineEdit(self)
  46.         self.email.setPlaceholderText('Please Enter Your Email')
  47.         self.email.setFont(QtGui.QFont("Sanserif", 15))
  48.         self.email.setStyleSheet('background:yellow')
  49.  
  50.         vbox.addWidget(self.email)
  51.  
  52.         self.button = QPushButton("Insert Data", self)
  53.         self.button.setStyleSheet('background:green')
  54.  
  55.         self.button.setFont(QtGui.QFont("Sanserif", 15))
  56.         vbox.addWidget(self.button)
  57.         self.button.clicked.connect(self.InsertData)
  58.  
  59.         self.setLayout(vbox)
  60.  
  61.         self.show()
  62.  
  63.  
  64.     def InsertData(self):
  65.           con = mdb.connect('localhost', 'root', '', 'pyqt5')
  66.           with con:
  67.             cur = con.cursor()
  68.  
  69.             cur.execute("INSERT INTO data(name, email)"
  70.                         "VALUES('%s', '%s')" % (''.join(self.name.text()),
  71.                                                   ''.join(self.email.text())))
  72.  
  73.  
  74.             QMessageBox.about(self,'Connection', 'Data Inserted Successfully')
  75.             self.close()
  76.  
  77.  
  78.  
  79. App = QApplication(sys.argv)
  80. window = Window()
  81. sys.exit(App.exec())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement