tags:

views:

38

answers:

2

dear all .. i'm newbee on python and pyqt, i try to make small program with pyqt, the program is running, when i press the return key its will show input dialog and if i input 1 on label1 will show "one" and if i press enter egain input dialog will show again and if i input 2 the problem is the label still show "one" not show "two", any body can help me ..? pls

this is my code:

import sys
from PyQt4 import QtGui, QtCore
class class InputDialog(QtGui.QWidget):
  def __init__(self, parent=None):
  QtGui.QWidget.__init__(self, parent)

    self.setGeometry(300, 300, 350, 80)
    self.resize(1024,768)
    self.setWindowTitle('InputDialog')

    self.label = QtGui.QLabel(self)
    self.label.setGeometry (10,10,80,20)
    self.label.setText("Operator :")

    self.label1 = QtGui.QLabel(self)
    self.label1.setGeometry(90,10,80,20)




def keyPressEvent(self, event):
    if event.key() == (QtCore.Qt.Key_Return):
        self.label1.clear()
        text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog', 'Enter Your name:')
        if ok and ok==1:
            self.label1.setText("one")
        elif ok and ok==2:
            self.label.setText("two")
    else:
        self.label1.setText("ok")


app = QtGui.QApplication(sys.argv)
ya = InputDialog()
ya.show()
app.exec_()

sorry for my bad english

+1  A: 

You said self.label instead of self.label1 where you change the text. In your keyPressEvent function.

thyrgle
A: 

right sir, but i allready change my write mistake with label1 its still not change, still display one not two, thank u for your reply sir : )

yusman
Why are you doing `if ok and ok==1` and `elif ok and ok==2`? Just check `if ok==1` and `elif ok==2`. See if that helps.
thyrgle
i did your advice if ok==1 and elif ok==2, but its still only display one , when i input 1 or 2 on dialog input, its make me wonder
yusman