0

I am writing a program which checks if user is root. If not an input dialog shows up for password. I have done this earlier too (inside some class) but lost the file somewhere.

if os.name == 'posix':
  if not os.getuid() == 0:
    input, ok = QtGui.QInputDialog.getText(None, 'Password',
                                                   'Enter password:', QtGui.QLineEdit.Password)
  if ok:
    #remaining code

The issue here is that this produces an error QWidget: Must construct a QApplication before a QPaintDevice

Is it only possible to bring up input dialog using UI class? or Is there any other solution to this?

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
sundar_ima
  • 3,604
  • 8
  • 33
  • 52

1 Answers1

0

You did'nt gave use the whole code but it seems that you are not following the basic guidelines of PyQt. Here is the minimum you need to have to create a correct pyqt app:

import sys
from PyQt5 import QtWidget

def main():
    app = QtWidget.QApplication(sys.argv)
    w = QtWidget.SOMEWIDGET()
    w.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
Plouff
  • 3,290
  • 2
  • 27
  • 45
  • Sorry for the late reply. What I want is to get only input dialog for typing password. With the above example how do I get the input dialog. The most example available in the net deals with `class Example(QtGui.QWidget):`. But in my case I just only need the input dialog. – sundar_ima Jan 14 '15 at 08:53