I am a greener of python. I am trying to create an application here is my all of code. The application will work if data are match successfully then it will show another window.
from PyQt4.QtCore import SIGNAL
from PyQt4.QtGui import QDialog, QApplication, QPushButton, QLineEdit, QFormLayout
from PyQt4 import QtCore, QtGui
import sys
import os
import MySQLdb as mdb
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.le = QLineEdit()
self.le.setObjectName("host")
self.le.setText("Host")
self.pb = QPushButton()
self.pb.setObjectName("connect")
self.pb.setText("Connect")
layout = QFormLayout()
layout.addWidget(self.le)
layout.addWidget(self.pb)
self.setLayout(layout)
self.connect(self.pb, SIGNAL("clicked()"),self.button_click)
self.setWindowTitle("Learning")
def button_click(self):
# shost is a QString object
shost = self.le.text()
if shost:
s_h = "127.0.0.1"
s_n = "root"
s_p = ""
s_d = "code"
s_cn = mdb.connect(s_h, s_n, s_p, s_d)
cursor = s_cn.cursor()
query = "SELECT * FROM `ac` WHERE `acc` = %s "
re = cursor.execute(query,(shost,))
if re:
ex = Example()
ex.show()
else:
print "no"
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def run(self):
os.startfile("hyt.exe")
def initUI(self):
QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
self.setToolTip('This is a <b>QWidget</b> widget')
btn1 = QtGui.QPushButton('Start', self)
btn1.resize(btn1.sizeHint())
btn1.move(20, 20)
btn1.clicked.connect(self.run)
qbtn = QtGui.QPushButton('Quit', self)
qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)
qbtn.resize(qbtn.sizeHint())
qbtn.move(150, 20)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Python Script')
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
But my problem is when i press button then it will be show Example() window . but here when i press button then it show the window for 1 second so how can i fix it ?
if re:
ex = Example()
ex.show()
else:
print "no"