blank window

Post here if you need help with creating a Graphical User Interface in Python.

blank window

Postby danfan » Wed Oct 30, 2013 6:51 pm

I have very limited understanding on writing gui windows or using python, I want a blank window to appear for 20 seconds? I can't figure out how to do it

Code: Select all
import sys
from PyQt4 import QtGui


def main():
   
    app = QtGui.QApplication(sys.argv)

    w = QtGui.QWidget()
    w.resize(250, 150)
    w.move(300, 300)
    w.setWindowTitle('Simple')
    w.show()
    import sleep from time
    sleep(20)
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
danfan
 
Posts: 14
Joined: Fri Oct 25, 2013 1:33 am

Re: blank window

Postby Marbelous » Thu Oct 31, 2013 9:32 pm

Code: Select all
import sleep from time?
Try
Code: Select all
from time import sleep

The rest looks OK but I haven't done any Qt for a while.
Marbelous
 
Posts: 138
Joined: Fri May 31, 2013 8:12 pm

Re: blank window

Postby micseydel » Thu Oct 31, 2013 9:33 pm

In the future, don't post code like that that you know doesn't run without saying so. You should have said that you were getting a syntax error, and if your IDE is any good, you should have known and said what line. (You very well may not be using a good IDE, which I don't blame you for, but consider changing.)
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1303
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: blank window

Postby danfan » Fri Nov 01, 2013 6:55 pm

this code worked but now i have no ideal what i want to do next, is there any good documents on how to use QT or youtube videos , can run QT creator but qt designer won't work? i guess it's all built into one program but qt designer is grayed off

Code: Select all
import sys
from PyQt4 import QtGui
from time import sleep

class Example(QtGui.QWidget):
   
    def __init__(self):
        super(Example, self).__init__()
       
        self.initUI()
       
    def initUI(self):               
       
        self.resize(250, 150)
        self.center()
       
        self.setWindowTitle('Center')   
        self.show()
       
    def center(self):
       
        qr = self.frameGeometry()
        cp = QtGui.QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())
       
       
def main():
    sleep(10)
    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()     
danfan
 
Posts: 14
Joined: Fri Oct 25, 2013 1:33 am

Re: blank window

Postby Marbelous » Fri Nov 01, 2013 7:55 pm

Google: rapid gui programming with python and qt pdf

It's a freely available PDF that has a nice intro to Python in the first few chapters and then gets into Qt with some very simple apps. Be warned though, Qt is an advanced GUI package and uses advanced concepts like signals and slots to handle events. This book assumes you understand programming (not necessarily python) with OOP. I personally decided to spend some time with good old fashioned Tkinter before I go back to work with Qt. Mainly because Tkinter comes with Python so it's always there for you but also to better learn basic event handling. At the time Qt was also more restrictive with its licensing rules but it has since loosened up. Tkinter is rather clunky when it comes to widget layout management, has no fancy WYSIWYG GUI Designer and makes apps that look like something from Window 95 but, as I said, it's always there so it's good to have it in your toolbox for those times when you just need a quick GUI for simple apps. I did try to learn both concurrently but it was confusing to my old, addled brain. YMMV (esp. if U R A :geek: ).
Marbelous
 
Posts: 138
Joined: Fri May 31, 2013 8:12 pm


Return to GUI

Who is online

Users browsing this forum: No registered users and 3 guests